gopherdata / gophernotes

The Go kernel for Jupyter notebooks and nteract.
MIT License
3.8k stars 264 forks source link

Error instantiating recursive type #208

Closed RafalSkolasinski closed 4 years ago

RafalSkolasinski commented 4 years ago

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 4 years ago

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 4 years ago

Would consider adding some warning in the readme for a meantime. It was very confusing.

cosmos72 commented 4 years ago

True. README.md updated.

cosmos72 commented 4 years ago

Fixed in commit 39e156a960494a8c772801bf5d066e85800d3f6a