Skip to content

Commit 8e55fb6

Browse files
Backport "Improve error reporting for missing members" to LTS (#20963)
Backports #19800 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents bdf09d6 + ede0d55 commit 8e55fb6

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,8 @@ object RefChecks {
622622

623623
val missingMethods = grouped.toList flatMap {
624624
case (name, syms) =>
625-
val withoutSetters = syms filterNot (_.isSetter)
626-
if (withoutSetters.nonEmpty) withoutSetters else syms
625+
syms.filterConserve(!_.isSetter)
626+
.distinctBy(_.signature) // Avoid duplication for similar definitions (#19731)
627627
}
628628

629629
def stubImplementations: List[String] = {
@@ -634,7 +634,7 @@ object RefChecks {
634634

635635
if (regrouped.tail.isEmpty)
636636
membersStrings(regrouped.head._2)
637-
else (regrouped.sortBy("" + _._1.name) flatMap {
637+
else (regrouped.sortBy(_._1.name.toString()) flatMap {
638638
case (owner, members) =>
639639
("// Members declared in " + owner.fullName) +: membersStrings(members) :+ ""
640640
}).init
@@ -653,7 +653,7 @@ object RefChecks {
653653
return
654654
}
655655

656-
for (member <- missing) {
656+
for (member <- missingMethods) {
657657
def showDclAndLocation(sym: Symbol) =
658658
s"${sym.showDcl} in ${sym.owner.showLocated}"
659659
def undefined(msg: String) =

tests/neg/i19731.check

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Error: tests/neg/i19731.scala:4:6 -----------------------------------------------------------------------------------
2+
4 |class F1 extends Foo: // error
3+
| ^
4+
| class F1 needs to be abstract, since def foo(): Unit in class F1 is not defined
5+
-- Error: tests/neg/i19731.scala:7:6 -----------------------------------------------------------------------------------
6+
7 |class F2 extends Foo: // error
7+
| ^
8+
| class F2 needs to be abstract, since:
9+
| it has 2 unimplemented members.
10+
| /** As seen from class F2, the missing signatures are as follows.
11+
| * For convenience, these are usable as stub implementations.
12+
| */
13+
| def foo(): Unit = ???
14+
| def foo(x: Int): Unit = ???
15+
-- Error: tests/neg/i19731.scala:16:6 ----------------------------------------------------------------------------------
16+
16 |class B1 extends Bar: // error
17+
| ^
18+
| class B1 needs to be abstract, since:
19+
| it has 2 unimplemented members.
20+
| /** As seen from class B1, the missing signatures are as follows.
21+
| * For convenience, these are usable as stub implementations.
22+
| */
23+
| // Members declared in B1
24+
| def foo(x: Int): Unit = ???
25+
|
26+
| // Members declared in Bar
27+
| def foo(): Unit = ???

tests/neg/i19731.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
trait Foo:
2+
def foo(): Unit
3+
4+
class F1 extends Foo: // error
5+
def foo(): Unit
6+
7+
class F2 extends Foo: // error
8+
def foo(): Unit
9+
def foo(x: Int): Unit
10+
11+
12+
trait Bar:
13+
def foo(): Unit
14+
def foo(x: Int): Unit
15+
16+
class B1 extends Bar: // error
17+
def foo(x: Int): Unit

0 commit comments

Comments
 (0)