Skip to content

Commit

Permalink
Merge pull request #14527 from dotty-staging/fix-14415
Browse files Browse the repository at this point in the history
Don't skip override tests when overridden is AbsOverride
  • Loading branch information
smarter committed Feb 21, 2022
2 parents cf9525c + 195add8 commit 3ca087c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions 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
21 changes: 21 additions & 0 deletions 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

0 comments on commit 3ca087c

Please sign in to comment.