diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 834cfba2a8a0..520c5d03e32e 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -208,15 +208,20 @@ object RefChecks { false precedesIn(parent.asClass.baseClasses) - // We can exclude pairs safely from checking only under two additional conditions + // We can exclude pairs safely from checking only under three additional conditions // - their signatures also match in the parent class. // See neg/i12828.scala for an example where this matters. // - They overriding/overridden appear in linearization order. // See neg/i5094.scala for an example where this matters. + // - The overridden symbol is not `abstract override`. For such symbols + // we need a more extensive test since the virtual super chain depends + // on the precise linearization order, which might be different for the + // subclass. See neg/i14415.scala. override def canBeHandledByParent(sym1: Symbol, sym2: Symbol, parent: Symbol): Boolean = isOverridingPair(sym1, sym2, parent.thisType) .showing(i"already handled ${sym1.showLocated}: ${sym1.asSeenFrom(parent.thisType).signature}, ${sym2.showLocated}: ${sym2.asSeenFrom(parent.thisType).signature} = $result", refcheck) && inLinearizationOrder(sym1, sym2, parent) + && !sym2.is(AbsOverride) def checkAll(checkOverride: (Symbol, Symbol) => Unit) = while hasNext do diff --git a/tests/neg/i14415.check b/tests/neg/i14415.check new file mode 100644 index 000000000000..596debf175dc --- /dev/null +++ b/tests/neg/i14415.check @@ -0,0 +1,5 @@ +-- [E164] Declaration Error: tests/neg/i14415.scala:21:6 --------------------------------------------------------------- +21 |class X extends E with D // error + | ^ + | error overriding method m in trait C of type (a: Int): Int; + | method m in trait D of type (a: Int): Int needs `abstract override` modifiers diff --git a/tests/neg/i14415.scala b/tests/neg/i14415.scala new file mode 100644 index 000000000000..8683766625ad --- /dev/null +++ b/tests/neg/i14415.scala @@ -0,0 +1,21 @@ +trait A { + def m(a:Int): Int +} + +trait B extends A { + override def m(a:Int): Int = { return a; } +} + +trait C extends A { + abstract override def m(a:Int):Int = { return super.m(a); } +} + +trait D extends B with C { + override def m(a:Int):Int = { return super.m(a); } +} + +trait E extends C with B { + abstract override def m(a:Int):Int = { return super.m(a); } +} + +class X extends E with D // error