diff --git a/_test/struct46.go b/_test/struct46.go new file mode 100644 index 00000000..a041d0bd --- /dev/null +++ b/_test/struct46.go @@ -0,0 +1,21 @@ +package main + +import "fmt" + +type A struct { + B string + C D +} + +type D struct { + E *A +} + +func main() { + a := &A{B: "b"} + a.C = D{E: a} + fmt.Println(a.C.E.B) +} + +// Output: +// b diff --git a/interp/run.go b/interp/run.go index e7b4d664..ffacb4f6 100644 --- a/interp/run.go +++ b/interp/run.go @@ -1860,9 +1860,12 @@ func doCompositeSparse(n *node, hasType bool) { c1 := c.child[1] field := n.typ.fieldIndex(c.child[0].ident) convertLiteralValue(c1, n.typ.field[field].typ.TypeOf()) - if c1.typ.cat == funcT { + switch { + case c1.typ.cat == funcT: values[field] = genFunctionWrapper(c1) - } else { + case isRecursiveStruct(n.typ.field[field].typ, n.typ.field[field].typ.rtype): + values[field] = genValueInterfacePtr(c1) + default: values[field] = genValue(c1) } }