interp: avoid panic in output value generation for recursive types

Fixes #1134.
This commit is contained in:
Marc Vertes
2021-06-11 17:44:12 +02:00
committed by GitHub
parent a6762d500c
commit b19afbfe93
2 changed files with 21 additions and 1 deletions

20
_test/issue-1134.go Normal file
View File

@@ -0,0 +1,20 @@
package main
type I interface {
Hello()
}
type T struct {
Name string
Child []*T
}
func (t *T) Hello() { println("Hello", t.Name) }
func main() {
var i I = new(T)
i.Hello()
}
// Output:
// Hello

View File

@@ -350,7 +350,7 @@ func genValueOutput(n *node, t reflect.Type) func(*frame) reflect.Value {
}
fallthrough
case n.anc.kind == returnStmt && n.anc.val.(*node).typ.ret[0].cat == interfaceT:
if len(n.anc.val.(*node).typ.ret[0].field) == 0 {
if nod, ok := n.anc.val.(*node); !ok || len(nod.typ.ret[0].field) == 0 {
// empty interface, do not wrap
return value
}