interp: fix redeclaration of an interface variable

Fixes #1404.
This commit is contained in:
Marc Vertes
2022-06-13 08:56:09 +00:00
committed by GitHub
parent 6c74ab7bec
commit 259f64cfd4
2 changed files with 23 additions and 1 deletions

22
_test/issue-1404.go Normal file
View File

@@ -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

View File

@@ -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 {