-
Notifications
You must be signed in to change notification settings - Fork 407
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
Stack overflow regression of recursive arbOption #487
Conversation
I don't agree this is a legit test case. Here's a very similar definition that does fine without the code as-is: case class Recur(option: Option[Recur])
implicit def arbRecur: Arbitrary[Recur] =
Arbitrary {
Gen.lzy(Arbitrary.arbitrary[Option[Recur]]).map(Recur(_))
} An even more idiomatic version might look like this: case class Recur(option: Option[Recur])
object Recur {
implicit val arbRecur: Arbitrary[Recur] = {
lazy val g: Gen[Recur] = Gen.lzy(Gen.option(g).map(Recur(_)))
Arbitrary(g)
}
} I think it's reasonable to require people to use |
I agree. That it worked before was a fluke. I guess the motivation was to produce a bug-fix release, and this would avoid a regression for existing test suites. |
78959d5
to
f328e24
Compare
Toying around with it further, it seems there is a way to avoid the stackoverflow regression for existing recursive definitions, but also keep the 90/10 weighting of Some/None. |
@ashawley I'd prefer to keep the existing weighting since I think it's more likely to produce interesting data by default. OK to close this? |
Have you looked at the new changes here? This preserves the existing weighting. |
That, or I'm not understanding what you mean by "existing". |
f328e24
to
d13a5de
Compare
Aha, I see your update. Sorry for the confusion! I'm still not convinced by this PR. There is a cost to using As before, you could just rewrite your test to use delay instead: implicit def arbRecur: Arbitrary[Recur] = Arbitrary {
Gen.delay(Arbitrary.arbitrary[Option[Recur]])
.map(Recur(_))
} My belief is that these kinds of self-referential What do you think? |
I'm happy to close. Again, I'm not invested in recursive Option, so I can't defend it. I'm trying to generate goodwill by avoiding a regression in bug fix release, and get ScalaCheck working again in the Community Build. I'll reopen a new PR that captures the the idiomatic version you want to support going forward. |
Perfect, thanks! I'm sorry to be so demanding, but I'm trying to step up into more of a maintainer-ish role here (to get things back on track). |
The change in #408 broke definitions of
Arbitrary[X]
where X is a class with a recursiveOption
value.One potential fix is to rollback #286 that was released in 1.14.0.Alternatively, we can just call-by-name the implicitArbitrary
ofarbOption
withGen.delay
, in case it is recursive.