diff --git a/_test/issue-1404.go b/_test/issue-1404.go new file mode 100644 index 000000000..192444f40 --- /dev/null +++ b/_test/issue-1404.go @@ -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 diff --git a/interp/cfg.go b/interp/cfg.go index c66b9c170..a3fda919a 100644 --- a/interp/cfg.go +++ b/interp/cfg.go @@ -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 {