diff options
author | Martin Odersky <odersky@gmail.com> | 2016-05-06 18:59:06 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-05-23 16:11:45 +0200 |
commit | 7a264eee7c903295693ea14e075267dfceea8db9 (patch) | |
tree | c01d502bc1a202c3c2147a4bad06ce41c4c5d103 /tests/neg | |
parent | 4baaa5ac03b165ef9b17922e85ef062460d002c9 (diff) | |
download | dotty-7a264eee7c903295693ea14e075267dfceea8db9.tar.gz dotty-7a264eee7c903295693ea14e075267dfceea8db9.tar.bz2 dotty-7a264eee7c903295693ea14e075267dfceea8db9.zip |
Test case
Diffstat (limited to 'tests/neg')
-rw-r--r-- | tests/neg/equality.scala | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/neg/equality.scala b/tests/neg/equality.scala new file mode 100644 index 000000000..a32db57c5 --- /dev/null +++ b/tests/neg/equality.scala @@ -0,0 +1,80 @@ +object equality { + + case class Str(str: String) + + case class Num(x: Int) + + case class Other(x: Int) + + trait Option[+T] + 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, OT <: Option[T], OU <: Option[U]] + (implicit e: Eq[T, U]): Eq[OT, OU] = Eq() + + def main(args: Array[String]): Unit = { + Some(Other(3)) == None + + val x = Str("abc") + x == x + + val n = Num(2) + val m = Num(3) + n == m + + Other(1) == Other(2) + + Some(x) == None + Some(x) == Some(Str("")) + val z: Option[Str] = Some(Str("abc")) + z == Some(x) + z == None + Some(x) == z + None == z + None == Some(Other(3)) + + Other(3) == null + Str("x") == null + null == Other(3) + null == Str("x") + null == null + + class Fruit + + implicit def eqFruit[A <: Fruit, B <: Fruit]: Eq[A, B] = Eq() + + class Apple extends Fruit + class Pear extends Fruit + val a = new Apple + val p = new Pear + val f: Fruit = a + a == p + p == a + f == p + p == f + Some(new Apple) == Some(new Pear) + + n match { + case None => // error + } + + x == Other(1) // error + Other(2) == x // error + Other(1) == z // error + z == Other(1) // error + n == None // error + + Some(new Apple) == Some(Str("xx")) // error + x == n // error + n == x // error + z == Some(n) // error + z == n // error + Some(n) == z // error + Some(n) == Some(Other(3)) // error + Some(Other(3)) == Some(n) // error + n == z // error + } +} |