Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't skip override tests when overridden is AbsOverride #14527

Merged
merged 1 commit into from Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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