aboutsummaryrefslogtreecommitdiff
path: root/tests/pos-special
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-11-05 14:13:14 +0100
committerMartin Odersky <odersky@gmail.com>2015-11-05 14:13:40 +0100
commit1e280d03886e3b20fa28661b0d25b6b11dec56f3 (patch)
tree1b0dcad7124c0e7cb9881f0c629fb01195fb5a48 /tests/pos-special
parent4b76eeaa13176aede421af3fe86c392c438b0e5d (diff)
downloaddotty-1e280d03886e3b20fa28661b0d25b6b11dec56f3.tar.gz
dotty-1e280d03886e3b20fa28661b0d25b6b11dec56f3.tar.bz2
dotty-1e280d03886e3b20fa28661b0d25b6b11dec56f3.zip
Handle variance unsoundness in scalac
The included test pos-special/variances-constr.scala demonstrates an unsoundness in the variance checking of scalac. Scalac excludes symbols owned by constructors from the checking. This is unsound, as can be demonstrated by compiling the test and observing output of the program run: Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String at Test$.main(variances-constr.scala:17) at Test.main(variances-constr.scala) Dotty allows this code only under -language:Scala2 and issues a migration warning.
Diffstat (limited to 'tests/pos-special')
-rw-r--r--tests/pos-special/variances-constr.scala21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/pos-special/variances-constr.scala b/tests/pos-special/variances-constr.scala
new file mode 100644
index 000000000..b210b0440
--- /dev/null
+++ b/tests/pos-special/variances-constr.scala
@@ -0,0 +1,21 @@
+class C[+A] {
+
+ private[this] var y: A = _
+ def getY: A = y
+
+ class Inner(x: A) {
+ y = x
+ }
+}
+
+object Test {
+
+ def main(args: Array[String]) = {
+ val x = new C[String]
+ val y: C[Any] = x
+ val i = new y.Inner(1)
+ val s: String = x.getY
+ println(s)
+ }
+}
+