From 24eb4c5bb5b3ed0e6bb4ede3e68876cdbe7d18fc Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Thu, 20 Oct 2011 22:28:39 +0000 Subject: no need to add an x field to everything however, it must be possible to inline Ensuring, ArrowAssoc methods renamed the public val x to something a little less intrusive fixed check file to reflect better error message (see! it wasn't that uncommon for people to write `foo.x` -- NEWS AT ELEVEN) no review --- src/library/scala/Predef.scala | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/library') 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) -- cgit v1.2.3