-
Notifications
You must be signed in to change notification settings - Fork 35
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
Avoiding generator failures when size is zero #50
Comments
Also, Gen.fail leads to a not particularly informative error message. Maybe ScalaCheck could support a reason ( |
This issue is derived as a result of this one fyi: nrinaudo/kantan.csv#59 |
@travisbrown I think your solution is probably the right one in the short-term. I was thinking of adding error-recovery combinators on @ScalaWilliam That's an interesting idea. I would prefer to minimize the usage of |
#51 seems to solve this issue, without resorting to catching stack overflows. But it it uses |
I've confirmed that #51 solves the issue as @travisbrown reported it. The following still fails, though: import org.scalacheck._, Shapeless._
sealed trait Or[+A, +B] extends Product with Serializable
case class Left[A](a: A) extends Or[A, Nothing]
case class Right[B](b: B) extends Or[Nothing, B]
val prop = Prop.forAll { (f: Int => Float Or Boolean) => f(0); true } And then:
|
Quick heads up here. If my understanding is correct, the problem is actually more serious than initially though - and doesn't have a quick fix, it seems. The problem here is we can't in a reliable way generate a recursive |
To workaround that, I may introduce two ways of deriving Arbitraries for coproducts,
One should be the default, the other would require a manual step to be enabled for a given type. |
Also, to clarify things, @travisbrown 's fix above wasn't fine with actually recursive ADTs (stack was blowing elsewhere), but things may be fine by catching the StackOverflow elsewhere... Trying that. |
I was actually wondering about this behaviour - that I'm wondering whether that's not a design flaw in the way arbitrary functions are built rather than a fault in scalacheck-shapeless. Generators that sometimes fail are part of the library's normal behaviour, and it's weird for them to cause arbitrary functions to fail. |
New fix pushed in #51. For a recursive type For non recursive types, nothing has to be done, they should be fine out of the box. |
Is there still a need for this, given typelevel/scalacheck#301? |
Failing generators are really bad now that we have non-constant arbitrary functions in ScalaCheck 1.13. Here's an example of a place this comes up in this library (derived from an example by @nrinaudo):
And:
I've taken a shot at a diagnosis here, but in short it looks like something like this in
MkCoproductArbitrary.ccons
would work:(I'd also just use
math.min(0, size - 1)
instead of thesignum
stuff, but that's not really relevant.)Catching the stack overflow is an awful hack, but it avoids the
Gen.fail
onsize == 0
for non-recursive ADTs while still not stack-overflowing for recursive ones.The text was updated successfully, but these errors were encountered: