Files
moxa/_test/struct50.go
Nicholas Wiersma a15ecb7176 feature: handle nested recursion
* fix: copy the type in recursion

In more advanced recursive cases, setting the rtype to interface may interfear with typeing. To stop this from happening, instead of setting t.val.rtype to interface in the hope it will be set correctly later, a copy if the type is made, and the rtype of the copy is set to interface{}.

* fix: detect intermediate recursive structs

In the case of a nested recussion, each symbol can have
a different perspective on the recursion. In this case,
it is impossible to move from one struct to the next.
To keep the perspectives the same, any intermediate struct
that contains a recursion should also be set to interface{}.
so that all perspectives are the same.

* fix: handle arb recursion

* chore: refactor dref to be consistent

* fix: invalid recursive struct issue

* fix: handle checkptr issue

* fix: move unsafe into function to stop ptr check

* fix: handle deref in assign
2020-07-02 23:20:03 +02:00

21 lines
335 B
Go

package main
import "fmt"
type Node struct {
Name string
Child []Node
}
func main() {
a := Node{Name: "hello"}
a.Child = append([]Node{}, Node{Name: "world"})
fmt.Println(a)
a.Child[0].Child = append([]Node{}, Node{Name: "sunshine"})
fmt.Println(a)
}
// Output:
// {hello [{world []}]}
// {hello [{world [{sunshine []}]}]}