-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Open
Description
Hi Quii,
While learning on the site, I noticed that the implementation of Walk would cause fatal error: stack overflow with this test
func TestWalk(t *testing.T) {
t.Run("walk with circular reference", func(t *testing.T) {
type Person struct {
Name string
Age int
Address string
Fren *Person
}
person := Person{
Name: "Alice",
Age: 30,
Address: "123 Main St",
}
person.Fren = &person
got := make([]string, 0)
Walk(person, func(s string) {
got = append(got, s)
})
expected := []string{"Alice", "123 Main St"}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Walk() = %v; want %v", got, expected)
}
})
}
where person.Fren refers to person itself (person is a go developer).
We should be able to solve it with a visitor implementation but I would like to know the preferable behavior before submitting a PR.
Thanks.
Metadata
Metadata
Assignees
Labels
No labels