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

testing/quick: stack overflow for recursive types #8818

Closed
philhofer opened this issue Sep 26, 2014 · 8 comments
Closed

testing/quick: stack overflow for recursive types #8818

philhofer opened this issue Sep 26, 2014 · 8 comments
Milestone

Comments

@philhofer
Copy link
Contributor

Recursive types will cause quick.Value to recurse infinitely. It never decides to make
recursive inner pointers 'nil.'

See: http://play.golang.org/p/ovrHvaPhVp

Perhaps if the inner type to be generated is the same as the parent type, it should
(probabilistically) be empty? (Or, in this case, since it's a pointer, it should just be
nil.)
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-go1.5.

@philhofer
Copy link
Contributor Author

I'm happy to take care of this if we can decide on the correct behavior.

@josharian
Copy link
Contributor

My 2c (not the final word): It seems reasonable in general for testing/quick to probabilistically generate nil pointers, even for non-recursive types. Issue #8461 is somewhat related. Such a change might cause tests that currently pass to start failing.

If you work on this, please be sure to also test mutually recursive types:

type (
    R struct{ r *R }

    S struct{ t *T }
    T struct{ s S }
)

// Issue 8818
// Generating values for recursive types used to hang.
func TestRecursiveType(t *testing.T) {
    if _, ok := Value(reflect.TypeOf(&R{}), rand.New(rand.NewSource(0))); !ok {
        t.Error("failed to generate recursive value")
    }

    if _, ok := Value(reflect.TypeOf(&S{}), rand.New(rand.NewSource(0))); !ok {
        t.Error("failed to generate mutually recursive value")
    }
}

@josharian
Copy link
Contributor

@bradfitz who is the right person to decide what the correct behavior is here?

@josharian
Copy link
Contributor

@robpike do you have an opinion here, or a 301?

@robpike
Copy link
Contributor

robpike commented May 9, 2015

@agl is the original author. Ask him.

@osocurioso
Copy link
Contributor

The documentation for quick.Value says: "Value returns an arbitrary value of the given type". Not generating nil pointers seems more like a bug than what was intended?

@gopherbot
Copy link

CL https://golang.org/cl/10821 mentions this issue.

@agl agl closed this as completed in 7089ea4 Jun 8, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants