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 git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@25858 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
972f8d438c
commit
59d43d74ca
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 )
|
||||
^
|
||||
^
|
||||
|
|
|
|||
Loading…
Reference in New Issue