From 3bbc2bf62cebcf6fd7cb22d6b3e1227095e7964a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 11 Dec 2015 09:03:12 +0100 Subject: Better diagnosis for cyclic references caused by class clashes. We now get a cyclic reference when inheriting from an inner class with the same name in an outer supertype. Since this was legal in Scala2 it's good to explain that particular case. Test case in overrideClass.scala --- tests/neg/overrideClass.scala | 20 ++++++++++++++++++++ tests/neg/overrides.scala | 19 ------------------- 2 files changed, 20 insertions(+), 19 deletions(-) create mode 100644 tests/neg/overrideClass.scala (limited to 'tests') diff --git a/tests/neg/overrideClass.scala b/tests/neg/overrideClass.scala new file mode 100644 index 000000000..803d97dd9 --- /dev/null +++ b/tests/neg/overrideClass.scala @@ -0,0 +1,20 @@ + abstract class FooA { + type A <: Ax; + abstract class Ax; + abstract class InnerA { + type B <: A; + def doB : B; + } + } + 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) + abstract class InnerB extends InnerA { + // type B <: A; + val a : A = doB; + a.xxx; + doB.xxx; + } + } + diff --git a/tests/neg/overrides.scala b/tests/neg/overrides.scala index 727759e3c..b7e598184 100644 --- a/tests/neg/overrides.scala +++ b/tests/neg/overrides.scala @@ -1,22 +1,3 @@ - abstract class FooA { - type A <: Ax; - abstract class Ax; - abstract class InnerA { - type B <: A; - def doB : B; - } - } - trait FooB extends FooA { - type A <: Ax; - trait Ax extends super.Ax { def xxx : Int; } // error: classes cannot be overridden - abstract class InnerB extends InnerA { - // type B <: A; - val a : A = doB; - a.xxx; - doB.xxx; - } - } - package p1 { abstract class T1 { protected def bug(p: Int = 1): Int // without 'protected' compiles fine -- cgit v1.2.3