Error instantiating recursive type
RafalSkolasinski opened this issue · 4 comments
RafalSkolasinski commented
When trying to create a simple graph structure - a struct
containing a slice of itself - I am getting problems in gophernotes
.
Same works fine in just plain go
file.
Code:
package main
import "fmt"
type Item struct {
Name string
Children []Item
}
graph := Item{
Name: "my-name",
Children: []Item{
{Name: "other-name"},
},
}
throws error (warning?)
reflect.Value.Convert: value of type []struct { Name string; Children []xreflect.Forward } cannot be converted to type []xreflect.Forward
cosmos72 commented
There are known limitations on recursive types, because they are emulated: the reflect
package cannot create them.
Yet, this should be one of the supported cases... thanks for pointing out, I will investigate
RafalSkolasinski commented
Would consider adding some warning in the readme for a meantime. It was very confusing.
cosmos72 commented
True. README.md updated.