diff options
author | Martin Odersky <odersky@gmail.com> | 2016-05-06 12:30:55 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-05-23 16:11:45 +0200 |
commit | cd8bf2d69cf1463fa16a69badb2a839f540bb2fa (patch) | |
tree | 4662148486993086b3f488cd5e41cc7219e5ff5b /tests/neg | |
parent | 3676baa4b1422f4ee46098aafc1ccd98f176bad4 (diff) | |
download | dotty-cd8bf2d69cf1463fa16a69badb2a839f540bb2fa.tar.gz dotty-cd8bf2d69cf1463fa16a69badb2a839f540bb2fa.tar.bz2 dotty-cd8bf2d69cf1463fa16a69badb2a839f540bb2fa.zip |
Hooks to check that comparisons with == / != make sense
Also, check that pattern matching against idents/selects/literals makes
sense.
The hooks perform an implicit search for an instance of `Eq[L, R]`, where
`L`, `R` are the argument types. So far this always succeeeds because Eq.eqAny
matches all such types. A separate commit will check the returned
search term for validity.
Diffstat (limited to 'tests/neg')
-rw-r--r-- | tests/neg/EqualityStrawman2.scala | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/tests/neg/EqualityStrawman2.scala b/tests/neg/EqualityStrawman2.scala deleted file mode 100644 index f71c7d3d7..000000000 --- a/tests/neg/EqualityStrawman2.scala +++ /dev/null @@ -1,96 +0,0 @@ -object equality { - - trait Eq[-T, -U] - object Eq extends Eq[Any, Any] - - implicit class EqualsDeco[T](val x: T) extends AnyVal { - def ===[U] (y: U)(implicit ce: Eq[T, U]) = x.equals(y) - } - - type EqEq[T] = Eq[T, T] - - trait EqClass - - implicit def eqAny: Eq[Any, Any] = Eq - - implicit def mixedEq1 : Eq[Any, EqClass] = Eq - implicit def mixedEq1alt: Eq[Any, EqClass] = Eq - implicit def mixedEq2 : Eq[EqClass, Any] = Eq - implicit def mixedEq2alt: Eq[EqClass, Any] = Eq - -// implicit def eqEq[U, T <: U with EqClass[U]]: Eq[T, T] = Eq - - case class Str(str: String) extends EqClass - case class Num(x: Int) extends EqClass - - case class Other(x: Int) - - trait Option[+T] extends EqClass - case class Some[+T](x: T) extends Option[T] - case object None extends Option[Nothing] - - implicit def eqStr: Eq[Str, Str] = Eq - implicit def eqNum: Eq[Num, Num] = Eq - implicit def eqOption[T, U](implicit ce: Eq[T, U]): Eq[Option[T], Option[U]] = Eq - - def main(args: Array[String]): Unit = { - val x = Str("abc") - (Some(x): Option[Str]) === (None: Option[Str]) - - x === x - - val n = Num(2) - val m = Num(3) - n === m - - Other(1) === Other(2) - - (Some(x) === None)//(eqOption) - (Some(x) === Some(Str("")))(eqOption) - val z: Option[Str] = Some(Str("abc")) - z === Some(x) - z === None - Some(x) === z - None === z -/* - Other(3) === null - Str("x") === null - null === Other(3) - null === Str("x") - null === null*/ - - class Fruit extends EqClass - class Apple extends Fruit - class Pear extends Fruit - implicit def eqFruit: Eq[Fruit, Fruit] = Eq - - Some(new Apple) === Some(new Pear) - - - def ddistinct[T: EqEq](xs: List[T]): List[T] = xs match { - case Nil => Nil - case x :: xs => x :: xs.filterNot(x === _) - } - - ddistinct(List(z, z, z)) - - n match { - case None => - } - - Some(new Apple) === Some(Str("xx")) // error - x === n // error - n === x // error - x === Other(1) // error - Other(2) === x // error - z === Some(n) // error - z === n // error - Some(n) === z // error - n === z // error - Other(1) === z // error - z === Other(1) // error - ddistinct(List(z, n)) // error - - - } -} |