Skip to content

Commit

Permalink
Deprecate Prop.BooleanOperators in anticipation of Dotty
Browse files Browse the repository at this point in the history
For a Boolean b and a prop p, the following is ambiguous in dotty:

    import Prop._
    b ==> p

Because Prop contains:

    implicit def BooleanOperators(b: => Boolean) = new ExtendedBoolean(b)
    implicit def propBoolean(b: Boolean): Prop = Prop(b)

And both ExtendedBoolean and Prop provide a `==>` method, the one in
`ExtendedBoolean` just forwards to the one in `Prop`. This is not
ambiguous in scalac because `Boolean` wins against `=> Boolean` but it
is in dotty (and intentionally so).

In general, it seems that all the methods in BooleanOperators are also
available on Prop, so BooleanOperators does not serve any purpose and
can be deprecated. We can then make it non-implicit in a subsequent
release of scalacheck (thus breaking source-compatiblity but not
binary-compatiblity) to finally be able to compile it with Dotty (which
also requires getting typelevel#423 in).
  • Loading branch information
smarter committed Aug 7, 2019
1 parent aaffe1e commit dfa446d
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions doc/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Sometimes, a specification takes the form of an implication. In ScalaCheck,
you can use the implication operator `==>`:

```scala
import org.scalacheck.Prop.{forAll, BooleanOperators}
import org.scalacheck.Prop.{forAll, propBoolean}

val propMakeList = forAll { n: Int =>
(n >= 0 && n < 10000) ==> (List.fill(n)("").length == n)
Expand All @@ -138,7 +138,7 @@ property holds. In the following trivial example, all cases where `n` is
non-zero will be thrown away:

```
scala> import org.scalacheck.Prop.{forAll, BooleanOperators}
scala> import org.scalacheck.Prop.{forAll, propBoolean}
scala> val propTrivial = forAll { n: Int =>
| (n == 0) ==> (n == 0)
Expand Down Expand Up @@ -254,7 +254,7 @@ tell you exactly what part is failing. Look at the following example, where
the different conditions of the property have been labeled differently:

```scala
import org.scalacheck.Prop.{forAll, BooleanOperators}
import org.scalacheck.Prop.{forAll, propBoolean}

val complexProp = forAll { (m: Int, n: Int) =>
val res = myMagicFunction(n, m)
Expand All @@ -281,7 +281,7 @@ scala> complexProp.check
It is also possible to write the label before the conditions like this:

```scala
import org.scalacheck.Prop.{forAll, BooleanOperators}
import org.scalacheck.Prop.{forAll, propBoolean}

val complexProp = forAll { (m: Int, n: Int) =>
val res = myMagicFunction(n, m)
Expand All @@ -299,7 +299,7 @@ the value of an intermediate calculation. See the following example, which
tries to specify multiplication in a somewhat naive way:

```scala
import org.scalacheck.Prop.{forAll, BooleanOperators, all}
import org.scalacheck.Prop.{forAll, propBoolean, all}

val propMul = forAll { (n: Int, m: Int) =>
val res = n*m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

package org.scalacheck

import Prop.BooleanOperators
import Prop.propBoolean

object PropertyFilterSampleSpecification extends Properties("PropertyFilterSample") {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.scalacheck

import Prop.{forAll, BooleanOperators}
import Prop.{forAll, propBoolean}
import Shrink.shrink
import ShrinkSpecification.shrinkClosure

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object StringUtils extends Properties("Examples.StringUtils") {
}

property("truncate.precond") = Prop.forAll { (s: String, n: Int) =>
import Prop.BooleanOperators
import Prop.propBoolean
(n >= 0) ==> {
val t = StringUtils.truncate(s, n)
(s.length <= n && t == s) ||
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/org/scalacheck/Prop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ object Prop {
/** Implicit method that makes a number of property operators on boolean
* values available in the current scope. See [[Prop.ExtendedBoolean]] for
* documentation on the operators. */
@deprecated("Use Prop.propBoolean instead.", since = "ScalaCheck 1.14.1")
implicit def BooleanOperators(b: => Boolean) = new ExtendedBoolean(b)

/** Implicit conversion of Boolean values to Prop values. */
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalacheck/commands/Commands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ trait Commands {
/** Wraps the run and postCondition methods in order not to leak the
* dependant Result type. */
private[Commands] def runPC(sut: Sut): (Try[String], State => Prop) = {
import Prop.BooleanOperators
import Prop.propBoolean
val r = Try(run(sut))
(r.map(_.toString), s => preCondition(s) ==> postCondition(s,r))
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/org/scalacheck/PropSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package org.scalacheck
import Prop.{
forAll, falsified, undecided, exception, passed, proved, all,
atLeastOne, sizedProp, someFailing, noneFailing, Undecided, False, True,
Exception, Proof, throws, BooleanOperators, secure, delay, lzy
Exception, Proof, throws, propBoolean, secure, delay, lzy
}
import Gen.{ const, fail, oneOf, listOf, Parameters }

Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/org/scalacheck/ShrinkSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

package org.scalacheck

import Prop.{forAll, forAllNoShrink, BooleanOperators}
import Prop.{forAll, forAllNoShrink, propBoolean}
import Shrink.shrink

import scala.concurrent.duration.{Duration, FiniteDuration}
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/org/scalacheck/examples/MathSpec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.scalacheck.examples

import org.scalacheck.Prop.{forAll, BooleanOperators}
import org.scalacheck.Prop.{forAll, propBoolean}

object MathSpec extends org.scalacheck.Properties("Math") {
property("sqrt") = forAll { n: Int =>
Expand Down

0 comments on commit dfa446d

Please sign in to comment.