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.dump stack overflow problem

nkbai opened this issue · comments

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)
}

I hope that fmt.sprintf and spew.dump work together in my project
how to ? thanks

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.

thanks ,i have removed spew.sdump from stringer method