Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spew.dump stack overflow problem #76

Open
nkbai opened this issue Dec 30, 2017 · 3 comments
Open

spew.dump stack overflow problem #76

nkbai opened this issue Dec 30, 2017 · 3 comments

Comments

@nkbai
Copy link

nkbai commented Dec 30, 2017

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)
}
@nkbai
Copy link
Author

nkbai commented Dec 30, 2017

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

@dmitshur
Copy link

dmitshur commented Dec 30, 2017

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.

@nkbai
Copy link
Author

nkbai commented Dec 31, 2017

thanks ,i have removed spew.sdump from stringer method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants