Skip to content

Commit 61cd930

Browse files
committed
Report only non-overridden unimplemented members
Previously, when a concrete class A had unimplemented members that are overridden, all overrides would be reported as unimplemented in the error message. This would produce error messages that are not accurate, and that suggest stubs that are not correct. This patch fixes the issue by reporting in the error message only the unimplemented members that are not overridden by other unimplemented members. Fixes #21335
1 parent bad02ab commit 61cd930

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,13 @@ object RefChecks {
698698
&& withMode(Mode.IgnoreCaptures)(mbrDenot.matchesLoosely(impl, alwaysCompareTypes = true)))
699699
.exists
700700

701+
/** Filter out symbols from `syms` that are overridden by a symbol appearing later in the list.
702+
* Symbols that are not overridden are kept. */
703+
def lastOverrides(syms: List[Symbol]): List[Symbol] =
704+
syms.foldLeft(Nil):
705+
case (acc, sym) if acc.exists(s => isOverridingPair(s, sym, clazz.thisType)) => acc
706+
case (acc, sym) => sym :: acc
707+
701708
/** The term symbols in this class and its baseclasses that are
702709
* abstract in this class. We can't use memberNames for that since
703710
* a concrete member might have the same signature as an abstract
@@ -708,7 +715,7 @@ object RefChecks {
708715
for bc <- clazz.baseClasses; sym <- bc.info.decls.toList do
709716
if sym.is(DeferredTerm) && !isImplemented(sym) && !ignoreDeferred(sym) then
710717
buf += sym
711-
buf.toList
718+
lastOverrides(buf.toList)
712719

713720
// 2. Check that only abstract classes have deferred members
714721
def checkNoAbstractMembers(): Unit = {

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)