diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/neg/t1843-variances.scala | 25 | ||||
-rw-r--r-- | tests/neg/variances.scala | 44 | ||||
-rw-r--r-- | tests/pos/t1843.scala | 2 | ||||
-rw-r--r-- | tests/pos/typers.scala | 2 | ||||
-rw-r--r-- | tests/pos/variances.scala | 3 |
5 files changed, 74 insertions, 2 deletions
diff --git a/tests/neg/t1843-variances.scala b/tests/neg/t1843-variances.scala new file mode 100644 index 000000000..e9b5c5d2d --- /dev/null +++ b/tests/neg/t1843-variances.scala @@ -0,0 +1,25 @@ +/** +* Scala Compiler Will Crash On this File +* ... Or Will It? +* +*/ + +object Crash { + trait UpdateType[A] + case class StateUpdate[+A](updateType : UpdateType[A], value : A) + case object IntegerUpdateType extends UpdateType[Integer] + + //However this method will cause a crash + def crash(updates: List[StateUpdate[_]]): Unit = { + updates match { + case Nil => + case u::us => + u match { + //Line below seems to be the crashing line + case StateUpdate(key, newValue) if (key == IntegerUpdateType) => + println("Requires a statement to induce the crash") + case _ => + } + } + } +} diff --git a/tests/neg/variances.scala b/tests/neg/variances.scala new file mode 100644 index 000000000..30390ad22 --- /dev/null +++ b/tests/neg/variances.scala @@ -0,0 +1,44 @@ +// Tests variance checking on default methods +import reflect.ClassTag + +class Foo[+A: ClassTag](x: A) { + + private[this] val elems: Array[A] = Array(x) + + def f[B](x: Array[B] = elems): Array[B] = x // (1) should give a variance error here or ... + +} + +object Test extends App { + + val foo: Foo[Object] = new Foo[String]("A") + + val arr = foo.f[Object]() + + arr(0) = new Integer(1) // (1) ... will give an ArrayStoreException here + +} + +class Outer[+A](x: A) { + + private[this] var elem: A = x + + def getElem: A = elem + + class Inner(constrParam: A) { // (2) should give a variance error here or ... + elem = constrParam + } + +} + +object Test2 extends App { + val o1: Outer[String] = new Outer[String]("A") + val o2: Outer[Object] = o1 + new o2.Inner(new Integer(1)) + + val x: String = o1.getElem // (2) ... will give a classcast exeption here + +} + + + diff --git a/tests/pos/t1843.scala b/tests/pos/t1843.scala index e9b5c5d2d..5e8554a93 100644 --- a/tests/pos/t1843.scala +++ b/tests/pos/t1843.scala @@ -5,7 +5,7 @@ */ object Crash { - trait UpdateType[A] + trait UpdateType[+A] case class StateUpdate[+A](updateType : UpdateType[A], value : A) case object IntegerUpdateType extends UpdateType[Integer] diff --git a/tests/pos/typers.scala b/tests/pos/typers.scala index a95af558e..b2d786c1c 100644 --- a/tests/pos/typers.scala +++ b/tests/pos/typers.scala @@ -32,7 +32,7 @@ object typers { } class List[+T] { - def :: (x: T) = new :: (x, this) + def :: [U >: T](x: U): List[U] = new :: (x, this) def len: Int = this match { case x :: xs1 => 1 + xs1.len diff --git a/tests/pos/variances.scala b/tests/pos/variances.scala new file mode 100644 index 000000000..db858fd5d --- /dev/null +++ b/tests/pos/variances.scala @@ -0,0 +1,3 @@ +trait C[+T <: C[T, U], -U <: C[T, U]] { + +} |