Skip to content

Commit 3ca087c

Browse files
authored
Merge pull request #14527 from dotty-staging/fix-14415
Don't skip override tests when overridden is AbsOverride
2 parents cf9525c + 195add8 commit 3ca087c

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,20 @@ object RefChecks {
208208
false
209209
precedesIn(parent.asClass.baseClasses)
210210

211-
// We can exclude pairs safely from checking only under two additional conditions
211+
// We can exclude pairs safely from checking only under three additional conditions
212212
// - their signatures also match in the parent class.
213213
// See neg/i12828.scala for an example where this matters.
214214
// - They overriding/overridden appear in linearization order.
215215
// See neg/i5094.scala for an example where this matters.
216+
// - The overridden symbol is not `abstract override`. For such symbols
217+
// we need a more extensive test since the virtual super chain depends
218+
// on the precise linearization order, which might be different for the
219+
// subclass. See neg/i14415.scala.
216220
override def canBeHandledByParent(sym1: Symbol, sym2: Symbol, parent: Symbol): Boolean =
217221
isOverridingPair(sym1, sym2, parent.thisType)
218222
.showing(i"already handled ${sym1.showLocated}: ${sym1.asSeenFrom(parent.thisType).signature}, ${sym2.showLocated}: ${sym2.asSeenFrom(parent.thisType).signature} = $result", refcheck)
219223
&& inLinearizationOrder(sym1, sym2, parent)
224+
&& !sym2.is(AbsOverride)
220225

221226
def checkAll(checkOverride: (Symbol, Symbol) => Unit) =
222227
while hasNext do

tests/neg/i14415.check

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- [E164] Declaration Error: tests/neg/i14415.scala:21:6 ---------------------------------------------------------------
2+
21 |class X extends E with D // error
3+
| ^
4+
| error overriding method m in trait C of type (a: Int): Int;
5+
| method m in trait D of type (a: Int): Int needs `abstract override` modifiers

tests/neg/i14415.scala

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
trait A {
2+
def m(a:Int): Int
3+
}
4+
5+
trait B extends A {
6+
override def m(a:Int): Int = { return a; }
7+
}
8+
9+
trait C extends A {
10+
abstract override def m(a:Int):Int = { return super.m(a); }
11+
}
12+
13+
trait D extends B with C {
14+
override def m(a:Int):Int = { return super.m(a); }
15+
}
16+
17+
trait E extends C with B {
18+
abstract override def m(a:Int):Int = { return super.m(a); }
19+
}
20+
21+
class X extends E with D // error

0 commit comments

Comments
 (0)