fix: compose recursion

This commit is contained in:
Nicholas Wiersma
2020-05-28 08:52:03 +02:00
committed by GitHub
parent 184623d81f
commit 5d78c8ae27
2 changed files with 26 additions and 2 deletions

21
_test/struct46.go Normal file
View File

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

View File

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