Skip to content

Commit

Permalink
Avoid ambiguous implicit errors with 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:
b ==> p
Because we have:
  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.

This commit fixes this by removing the `==>` method from
`ExtendedBoolean`, this may break code that explicitly imported
`BooleanOperators` but not `propBoolean`, the fix is to also import `propBoolean`.
  • Loading branch information
smarter authored and allanrenucci committed Sep 14, 2018
1 parent 0a98a51 commit 00f01af
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 27 deletions.
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
20 changes: 0 additions & 20 deletions src/main/scala/org/scalacheck/Prop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -330,31 +330,11 @@ object Prop {
def =?(y: T) = Prop.=?(x, y)
}

/** A collection of property operators on `Boolean` values.
* Import [[Prop.BooleanOperators]] to make the operators available. */
class ExtendedBoolean(b: => Boolean) {
/** See the documentation for [[org.scalacheck.Prop]] */
def ==>(p: => Prop) = Prop(b) ==> p
/** See the documentation for [[org.scalacheck.Prop]] */
def :|(l: String) = Prop(b) :| l
/** See the documentation for [[org.scalacheck.Prop]] */
def |:(l: String) = l |: Prop(b)
/** See the documentation for [[org.scalacheck.Prop]] */
def :|(l: Symbol) = Prop(b) :| l
/** See the documentation for [[org.scalacheck.Prop]] */
def |:(l: Symbol) = l |: Prop(b)
}

/** Implicit method that makes a number of property operators on values of
* type `Any` available in the current scope.
* See [[Prop.ExtendedAny]] for documentation on the operators. */
implicit def AnyOperators[T](x: => T)(implicit ev: T => Pretty): ExtendedAny[T] = new ExtendedAny[T](x)

/** 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. */
implicit def BooleanOperators(b: => Boolean): ExtendedBoolean = new ExtendedBoolean(b)

/** Implicit conversion of Boolean values to Prop values. */
implicit def propBoolean(b: Boolean): Prop = Prop(b)

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 00f01af

Please sign in to comment.