diff --git a/_test/issue-1007.go b/_test/issue-1007.go new file mode 100644 index 000000000..54d3c702f --- /dev/null +++ b/_test/issue-1007.go @@ -0,0 +1,40 @@ +package main + +type TypeA struct { + B TypeB +} + +type TypeB struct { + C1 *TypeC + C2 *TypeC +} + +type TypeC struct { + Val string + D *TypeD + D2 *TypeD +} + +type TypeD struct { + Name string +} + +func build() *TypeA { + return &TypeA{ + B: TypeB{ + C2: &TypeC{Val: "22"}, + }, + } +} + +func Bar(s string) string { + a := build() + return s + "-" + a.B.C2.Val +} + +func main() { + println(Bar("test")) +} + +// Output: +// test-22 diff --git a/interp/type.go b/interp/type.go index b92ef6bac..6fde115d8 100644 --- a/interp/type.go +++ b/interp/type.go @@ -1551,7 +1551,7 @@ func hasRecursiveStruct(t *itype, defined map[string]*itype) bool { defined[typ.path+"/"+typ.name] = typ for _, f := range typ.field { - if hasRecursiveStruct(f.typ, defined) { + if hasRecursiveStruct(f.typ, copyDefined(defined)) { return true } }