aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-01-29 17:54:30 +1100
committerGuillaume Martres <smarter@ubuntu.com>2017-01-29 14:44:30 +0100
commit56fb15888fb98e3a6a535f5734bb8ce82fcd76c3 (patch)
treec1e01cce8a76a5e66ba2a54472bc899ae41ca405 /tests
parent6e8933ccc40bbfe1a92c32c2d8314fd6facef12a (diff)
downloaddotty-56fb15888fb98e3a6a535f5734bb8ce82fcd76c3.tar.gz
dotty-56fb15888fb98e3a6a535f5734bb8ce82fcd76c3.tar.bz2
dotty-56fb15888fb98e3a6a535f5734bb8ce82fcd76c3.zip
Fix #1750: Handle illegal class overrides better
Illegal class overrides are fundamentally at odds with the way dotty represents types and therefore can cause lots of low-level problems. Two measures in this commit First, we detect direct illegal class overrides on completion instead of during RefChecks. Break the override by making the previously overriding type private. This fixes i1750.scala, but still fails for indirect overrides between two unrelated outer traits/classes that are inherited by the same class or trait. We fix this by catching the previously thrown ClassCastException in both ExtractAPI and RefChecks. Test case for indirect overrides is in i1750a.scala.
Diffstat (limited to 'tests')
-rw-r--r--tests/neg/customArgs/overrideClass.scala3
-rw-r--r--tests/neg/i1750.scala12
-rw-r--r--tests/neg/i1750a.scala13
-rw-r--r--tests/neg/i1806.scala2
-rw-r--r--tests/neg/overrides.scala5
-rw-r--r--tests/neg/t7278.scala2
6 files changed, 28 insertions, 9 deletions
diff --git a/tests/neg/customArgs/overrideClass.scala b/tests/neg/customArgs/overrideClass.scala
index 803d97dd9..431b846d9 100644
--- a/tests/neg/customArgs/overrideClass.scala
+++ b/tests/neg/customArgs/overrideClass.scala
@@ -8,8 +8,7 @@
}
trait FooB extends FooA {
type A <: Ax;
- trait Ax extends super.Ax { def xxx : Int; } // error: cyclic inheritance: trait Ax extends itself
- // (Note that inheriting a class of the same name is no longer allowed)
+ trait Ax extends super.Ax { def xxx : Int; } // error: cyclic inheritance: trait Ax extends itself) // error: class definitions cannot be overridden
abstract class InnerB extends InnerA {
// type B <: A;
val a : A = doB;
diff --git a/tests/neg/i1750.scala b/tests/neg/i1750.scala
new file mode 100644
index 000000000..a2ebe8f2b
--- /dev/null
+++ b/tests/neg/i1750.scala
@@ -0,0 +1,12 @@
+trait Lang1 {
+ trait Exp
+ trait Visitor { def f(left: Exp): Unit }
+ class Eval1 extends Visitor { self =>
+ def f(left: Exp) = ()
+ }
+}
+trait Lang2 extends Lang1 {
+ class Visitor extends Eval1 { Visitor => // error: classes cannot be overridden
+ }
+}
+
diff --git a/tests/neg/i1750a.scala b/tests/neg/i1750a.scala
new file mode 100644
index 000000000..cbb5bec95
--- /dev/null
+++ b/tests/neg/i1750a.scala
@@ -0,0 +1,13 @@
+trait Lang1 {
+ trait Exp
+ trait Visitor { def f(left: Exp): Unit }
+ class Eval1 extends Visitor { self =>
+ def f(left: Exp) = ()
+ }
+}
+trait Lang3 { self: Lang1 =>
+ class Visitor extends Eval1 { Visitor => // error: classes cannot be overridden
+ }
+}
+trait Lang4 extends Lang1 with Lang3
+
diff --git a/tests/neg/i1806.scala b/tests/neg/i1806.scala
index 7e5e132f2..199ab4791 100644
--- a/tests/neg/i1806.scala
+++ b/tests/neg/i1806.scala
@@ -2,6 +2,6 @@ trait A {
class Inner
}
trait B extends A {
- class Inner extends super.Inner // error
+ class Inner extends super.Inner // error // error
}
diff --git a/tests/neg/overrides.scala b/tests/neg/overrides.scala
index 81a93a7a2..149220bd5 100644
--- a/tests/neg/overrides.scala
+++ b/tests/neg/overrides.scala
@@ -34,11 +34,6 @@ package p2 { // all being in the same package compiles fine
}
}
- abstract class T3 extends T2 {
- class A { // error: classes cannot be overridden
- bug()
- }
- }
}
class A[T] {
diff --git a/tests/neg/t7278.scala b/tests/neg/t7278.scala
index 643a3c858..7b13535f0 100644
--- a/tests/neg/t7278.scala
+++ b/tests/neg/t7278.scala
@@ -1,5 +1,5 @@
class A { class E }
-class B extends A { class E }
+class B extends A { class EB }
trait C { type E = Int }
trait D { type E = String }
trait EC { type E }