diff options
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 7 | ||||
-rw-r--r-- | test/dotc/tests.scala | 3 | ||||
-rw-r--r-- | tests/neg/overrideClass.scala | 20 | ||||
-rw-r--r-- | tests/neg/overrides.scala | 19 |
4 files changed, 28 insertions, 21 deletions
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 7f85badf5..b24916be8 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -579,7 +579,12 @@ class Namer { typer: Typer => else { val pt = checkClassTypeWithStablePrefix(ptype, parent.pos, traitReq = parent ne parents.head) if (pt.derivesFrom(cls)) { - ctx.error(i"cyclic inheritance: $cls extends itself", parent.pos) + val addendum = parent match { + case Select(qual: Super, _) if ctx.scala2Mode => + "\n(Note that inheriting a class of the same name is no longer allowed)" + case _ => "" + } + ctx.error(i"cyclic inheritance: $cls extends itself$addendum", parent.pos) defn.ObjectType } else pt diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index dc7f3179d..c57f32b58 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -121,7 +121,8 @@ class tests extends CompilerTest { @Test def neg_autoTupling2 = compileFile(negDir, "autoTuplingTest", xerrors = 3) @Test def neg_companions = compileFile(negDir, "companions", xerrors = 1) @Test def neg_over = compileFile(negDir, "over", xerrors = 3) - @Test def neg_overrides = compileFile(negDir, "overrides", xerrors = 11) + @Test def neg_overrides = compileFile(negDir, "overrides", xerrors = 10) + @Test def neg_overrideClass = compileFile(negDir, "overrideClass", List("-language:Scala2"), xerrors = 1) @Test def neg_i39 = compileFile(negDir, "i39", xerrors = 2) @Test def neg_i50_volatile = compileFile(negDir, "i50-volatile", xerrors = 6) @Test def neg_zoo = compileFile(negDir, "zoo", xerrors = 12) 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 |