diff options
-rw-r--r-- | src/library/scala/Predef.scala | 20 | ||||
-rw-r--r-- | test/files/buildmanager/t2556_3/t2556_3.check | 10 |
2 files changed, 15 insertions, 15 deletions
diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala index 27197364c9..1d3239a176 100644 --- a/src/library/scala/Predef.scala +++ b/src/library/scala/Predef.scala @@ -214,11 +214,14 @@ object Predef extends LowPriorityImplicits { throw new IllegalArgumentException("requirement failed: "+ message) } - final class Ensuring[A](val x: A) { - def ensuring(cond: Boolean): A = { assert(cond); x } - def ensuring(cond: Boolean, msg: => Any): A = { assert(cond, msg); x } - def ensuring(cond: A => Boolean): A = { assert(cond(x)); x } - def ensuring(cond: A => Boolean, msg: => Any): A = { assert(cond(x), msg); x } + final class Ensuring[A](val __resultOfEnsuring: A) { // `__resultOfEnsuring` must be a public val to allow inlining + // the val used to be called `x`, but now goes by `__resultOfEnsuring`, as that reduces the chances of a user's writing + // `foo.__resultOfEnsuring` and being confused why they get an ambiguous implicit conversion error + // (`foo.x` used to produce this error since both any2Ensuring and any2ArrowAssoc pimped an `x` onto everything) + def ensuring(cond: Boolean): A = { assert(cond); __resultOfEnsuring } + def ensuring(cond: Boolean, msg: => Any): A = { assert(cond, msg); __resultOfEnsuring } + def ensuring(cond: A => Boolean): A = { assert(cond(__resultOfEnsuring)); __resultOfEnsuring } + def ensuring(cond: A => Boolean, msg: => Any): A = { assert(cond(__resultOfEnsuring), msg); __resultOfEnsuring } } implicit def any2Ensuring[A](x: A): Ensuring[A] = new Ensuring(x) @@ -241,8 +244,11 @@ object Predef extends LowPriorityImplicits { def unapply[A, B, C](x: Tuple3[A, B, C]): Option[Tuple3[A, B, C]] = Some(x) } - final class ArrowAssoc[A](val x: A) { - @inline def -> [B](y: B): Tuple2[A, B] = Tuple2(x, y) + final class ArrowAssoc[A](val __leftOfArrow: A) { // `__leftOfArrow` must be a public val to allow inlining + // the val used to be called `x`, but now goes by `__leftOfArrow`, as that reduces the chances of a user's writing + // `foo.__leftOfArrow` and being confused why they get an ambiguous implicit conversion error + // (`foo.x` used to produce this error since both any2Ensuring and any2ArrowAssoc pimped an `x` onto everything) + @inline def -> [B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y) def →[B](y: B): Tuple2[A, B] = ->(y) } implicit def any2ArrowAssoc[A](x: A): ArrowAssoc[A] = new ArrowAssoc(x) diff --git a/test/files/buildmanager/t2556_3/t2556_3.check b/test/files/buildmanager/t2556_3/t2556_3.check index bf26602494..72236ca0d1 100644 --- a/test/files/buildmanager/t2556_3/t2556_3.check +++ b/test/files/buildmanager/t2556_3/t2556_3.check @@ -7,12 +7,6 @@ Changes: Map(class A -> List(), class B -> List(Changed(Class(B))[List((A,Object invalidate C.scala because parents have changed [Changed(Class(B))[List((A,Object), (ScalaObject,ScalaObject))]] invalidate B.scala because it references invalid (no longer inherited) definition [ParentChanged(Class(C))] compiling Set(B.scala, C.scala) -B.scala:3: error: type mismatch; - found : C - required: ?{val x: ?} -Note that implicit conversions are not applicable because they are ambiguous: - both method any2Ensuring in object Predef of type [A](x: A)Ensuring[A] - and method any2ArrowAssoc in object Predef of type [A](x: A)ArrowAssoc[A] - are possible conversion functions from C to ?{val x: ?} +B.scala:3: error: value x is not a member of C println( (new C).x ) - ^ + ^ |