summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2011-10-20 22:28:39 +0000
committerAdriaan Moors <adriaan.moors@epfl.ch>2011-10-20 22:28:39 +0000
commit24eb4c5bb5b3ed0e6bb4ede3e68876cdbe7d18fc (patch)
tree21c1260adb14a8e3b8fbfd2dee484ab62d6cc8a4 /src/library
parent612f87b3d3ed214ca2f1753de923720fd2948aee (diff)
downloadscala-24eb4c5bb5b3ed0e6bb4ede3e68876cdbe7d18fc.tar.gz
scala-24eb4c5bb5b3ed0e6bb4ede3e68876cdbe7d18fc.tar.bz2
scala-24eb4c5bb5b3ed0e6bb4ede3e68876cdbe7d18fc.zip
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
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/Predef.scala20
1 files changed, 13 insertions, 7 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)