Skip to content

Commit

Permalink
interp: fix redeclaration of an interface variable
Browse files Browse the repository at this point in the history
Fixes #1404.
  • Loading branch information
mvertes authored Jun 13, 2022
1 parent 6c74ab7 commit 259f64c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions _test/issue-1404.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

type I interface {
inI()
}

type T struct {
name string
}

func (t *T) inI() {}

func main() {
var i I = &T{name: "foo"}

if i, ok := i.(*T); ok {
println(i.name)
}
}

// Output:
// foo
2 changes: 1 addition & 1 deletion interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,7 @@ func compDefineX(sc *scope, n *node) error {
for i, t := range types {
var index int
id := n.child[i].ident
if sym, level, ok := sc.lookup(id); ok && level == n.child[i].level && sym.kind == varSym && sym.typ.equals(t) {
if sym, level, ok := sc.lookup(id); ok && level == n.child[i].level && sym.kind == varSym && sym.typ.id() == t.id() {
// Reuse symbol in case of a variable redeclaration with the same type.
index = sym.index
} else {
Expand Down

0 comments on commit 259f64c

Please sign in to comment.