davecgh / go-spew

Implements a deep pretty printer for Go data structures to aid in debugging

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spew fails to detect cycles in []interface{} values

kortschak opened this issue · comments

Reproducer:

package main

import "github.com/davecgh/go-spew/spew"

func main() {
    r := make([]interface{}, 1)
    r[0] = r
    spew.Dump(r)
}

See kortschak#5

Fix for the slice case at kortschak#7.

Nice find! I'll take at a look at the proposed fix and get this updated accordingly.

Fixing this should also fix #44.

I suspect that interface pointers in general will need to be saved since it could really happen with any compound data structure that contains an interface due to them really just being a reference.

It can only happen with pointer or pointer-like types. So for example, you do not get the effect with type T struct { F interface{} }; v := T{}; v.F = v. So this means it's just limited to maps, slices and pointers. I have a partial fix for maps, but it need mores work.

Here is a fix for maps kortschak#8.