spew.dump stack overflow problem
nkbai opened this issue · comments
steven commented
package main
import "github.com/davecgh/go-spew/spew"
type A struct {
AMember int
}
func (this *A) String() string {
return spew.Sdump(this)
}
type B struct {
BMember A
}
func main() {
spew.Config.DisableMethods = false
b := &B{A{32}}
spew.Dump(b)
}
steven commented
I hope that fmt.sprintf and spew.dump work together in my project
how to ? thanks
Dmitri Shuralyov commented
When you execute spew.Sdump(this)
in the A.String
method, spew runs, sees that the type A
implements the fmt.Stringer
interface, and calls String
, which in turn calls spew again. So it recurses forever.
You shouldn’t call spew in a String
method.
steven commented
thanks ,i have removed spew.sdump from stringer method