aboutsummaryrefslogtreecommitdiff
path: root/tests/neg
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-07-20 14:48:34 +0200
committerMartin Odersky <odersky@gmail.com>2014-08-03 17:28:34 +0200
commite33a7385268084138e3d51faffdff33b540ad942 (patch)
treeae547106f6a363c5487535393bc1f971441bc55f /tests/neg
parent38761d9d11a42635e64d6df54ecaf1968797e7e8 (diff)
downloaddotty-e33a7385268084138e3d51faffdff33b540ad942.tar.gz
dotty-e33a7385268084138e3d51faffdff33b540ad942.tar.bz2
dotty-e33a7385268084138e3d51faffdff33b540ad942.zip
Enabled variance checking
Variance checking is now run as part of type-checking. Fixed tests that exhibited variance errors. Added tests where some classes of variance errors should be detected.
Diffstat (limited to 'tests/neg')
-rw-r--r--tests/neg/t1843-variances.scala25
-rw-r--r--tests/neg/variances.scala44
2 files changed, 69 insertions, 0 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
+
+}
+
+
+