Skip to content

Commit

Permalink
Stack overflow regression of recursive arbOption
Browse files Browse the repository at this point in the history
  • Loading branch information
ashawley committed Aug 6, 2019
1 parent 1e83007 commit f328e24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions jvm/src/test/scala/org/scalacheck/ArbitrarySpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ object ArbitrarySpecification extends Properties("Arbitrary") {
property("arbOption coverage") =
exists(genOptionUnits) { case (a, b) => a.isDefined != b.isDefined }

private[this] final case class Recur(opt: Option[Recur])

private[this] implicit def arbRecur: Arbitrary[Recur] = Arbitrary {
Arbitrary.arbitrary[Option[Recur]]
.map(Recur(_))
}

property("arbitrary[Recur]") = {
Prop.forAll { recOpt: Recur =>
Prop.passed
}
}

property("arbEnum") = {
Gen.listOfN(100, arbitrary[TimeUnit]).sample.get.toSet == TimeUnit.values.toSet
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalacheck/Arbitrary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private[scalacheck] sealed trait ArbitraryLowPriority {

/** Arbitrary instance of the Option type */
implicit def arbOption[T](implicit a: Arbitrary[T]): Arbitrary[Option[T]] =
Arbitrary(Gen.option(a.arbitrary))
Arbitrary(Gen.option(Gen.delay(a.arbitrary)))

/** Arbitrary instance of the Either type */
implicit def arbEither[T, U](implicit at: Arbitrary[T], au: Arbitrary[U]): Arbitrary[Either[T, U]] =
Expand Down

0 comments on commit f328e24

Please sign in to comment.