Skip to content

Commit

Permalink
Backport "Report only non-overridden unimplemented members" to 3.5.2 (#…
Browse files Browse the repository at this point in the history
…21484)

Backports #21337 to the 3.5.2 branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Aug 28, 2024
2 parents d4df4b9 + cc37466 commit 32e21bd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
12 changes: 11 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,15 @@ object RefChecks {
&& withMode(Mode.IgnoreCaptures)(mbrDenot.matchesLoosely(impl, alwaysCompareTypes = true)))
.exists

/** Filter out symbols from `syms` that are overridden by a symbol appearing later in the list.
* Symbols that are not overridden are kept. */
def lastOverrides(syms: List[Symbol]): List[Symbol] =
val deduplicated =
syms.foldLeft(List.empty[Symbol]):
case (acc, sym) if acc.exists(s => isOverridingPair(s, sym, clazz.thisType)) => acc
case (acc, sym) => sym :: acc
deduplicated.reverse

/** The term symbols in this class and its baseclasses that are
* abstract in this class. We can't use memberNames for that since
* a concrete member might have the same signature as an abstract
Expand All @@ -717,7 +726,8 @@ object RefChecks {

val missingMethods = grouped.toList flatMap {
case (name, syms) =>
syms.filterConserve(!_.isSetter)
lastOverrides(syms)
.filterConserve(!_.isSetter)
.distinctBy(_.signature) // Avoid duplication for similar definitions (#19731)
}

Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i21335.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Error: tests/neg/i21335.scala:7:6 -----------------------------------------------------------------------------------
7 |class Z1 extends Bar1 // error
| ^
| class Z1 needs to be abstract, since override def bar(): Bar1 in trait Bar1 is not defined
-- Error: tests/neg/i21335.scala:12:6 ----------------------------------------------------------------------------------
12 |class Z2 extends Bar2 // error
| ^
| class Z2 needs to be abstract, since def bar(): Bar2 in trait Bar2 is not defined
12 changes: 12 additions & 0 deletions tests/neg/i21335.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
trait Foo:
def bar(): Foo

trait Bar1 extends Foo:
override def bar(): Bar1

class Z1 extends Bar1 // error

trait Bar2 extends Foo:
def bar(): Bar2

class Z2 extends Bar2 // error

0 comments on commit 32e21bd

Please sign in to comment.