Skip to content

Commit 32e21bd

Browse files
Backport "Report only non-overridden unimplemented members" to 3.5.2 (#21484)
Backports #21337 to the 3.5.2 branch. PR submitted by the release tooling. [skip ci]
2 parents d4df4b9 + cc37466 commit 32e21bd

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,15 @@ object RefChecks {
695695
&& withMode(Mode.IgnoreCaptures)(mbrDenot.matchesLoosely(impl, alwaysCompareTypes = true)))
696696
.exists
697697

698+
/** Filter out symbols from `syms` that are overridden by a symbol appearing later in the list.
699+
* Symbols that are not overridden are kept. */
700+
def lastOverrides(syms: List[Symbol]): List[Symbol] =
701+
val deduplicated =
702+
syms.foldLeft(List.empty[Symbol]):
703+
case (acc, sym) if acc.exists(s => isOverridingPair(s, sym, clazz.thisType)) => acc
704+
case (acc, sym) => sym :: acc
705+
deduplicated.reverse
706+
698707
/** The term symbols in this class and its baseclasses that are
699708
* abstract in this class. We can't use memberNames for that since
700709
* a concrete member might have the same signature as an abstract
@@ -717,7 +726,8 @@ object RefChecks {
717726

718727
val missingMethods = grouped.toList flatMap {
719728
case (name, syms) =>
720-
syms.filterConserve(!_.isSetter)
729+
lastOverrides(syms)
730+
.filterConserve(!_.isSetter)
721731
.distinctBy(_.signature) // Avoid duplication for similar definitions (#19731)
722732
}
723733

tests/neg/i21335.check

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Error: tests/neg/i21335.scala:7:6 -----------------------------------------------------------------------------------
2+
7 |class Z1 extends Bar1 // error
3+
| ^
4+
| class Z1 needs to be abstract, since override def bar(): Bar1 in trait Bar1 is not defined
5+
-- Error: tests/neg/i21335.scala:12:6 ----------------------------------------------------------------------------------
6+
12 |class Z2 extends Bar2 // error
7+
| ^
8+
| class Z2 needs to be abstract, since def bar(): Bar2 in trait Bar2 is not defined

tests/neg/i21335.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait Foo:
2+
def bar(): Foo
3+
4+
trait Bar1 extends Foo:
5+
override def bar(): Bar1
6+
7+
class Z1 extends Bar1 // error
8+
9+
trait Bar2 extends Foo:
10+
def bar(): Bar2
11+
12+
class Z2 extends Bar2 // error

0 commit comments

Comments
 (0)