Skip to content

Commit 1f7789f

Browse files
committed
Improve error reporting for missing members
Co-Authored-By: [email protected] Co-Authored-By: [email protected] Co-Authored-By: [email protected]
1 parent 7f410aa commit 1f7789f

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ object RefChecks {
654654

655655
val missingMethods = grouped.toList flatMap {
656656
case (name, syms) =>
657-
val withoutSetters = syms filterNot (_.isSetter)
658-
if (withoutSetters.nonEmpty) withoutSetters else syms
657+
syms.filterConserve(!_.isSetter)
658+
.distinctBy(_.signature) // Avoid duplication for similar definitions (#19731)
659659
}
660660

661661
def stubImplementations: List[String] = {
@@ -666,7 +666,7 @@ object RefChecks {
666666

667667
if (regrouped.tail.isEmpty)
668668
membersStrings(regrouped.head._2)
669-
else (regrouped.sortBy("" + _._1.name) flatMap {
669+
else (regrouped.sortBy(_._1.name.toString()) flatMap {
670670
case (owner, members) =>
671671
("// Members declared in " + owner.fullName) +: membersStrings(members) :+ ""
672672
}).init
@@ -685,7 +685,7 @@ object RefChecks {
685685
return
686686
}
687687

688-
for (member <- missing) {
688+
for (member <- missingMethods) {
689689
def showDclAndLocation(sym: Symbol) =
690690
s"${sym.showDcl} in ${sym.owner.showLocated}"
691691
def undefined(msg: String) =
@@ -1002,9 +1002,9 @@ object RefChecks {
10021002
end checkNoPrivateOverrides
10031003

10041004
def checkVolatile(sym: Symbol)(using Context): Unit =
1005-
if sym.isVolatile && !sym.is(Mutable) then
1005+
if sym.isVolatile && !sym.is(Mutable) then
10061006
report.warning(VolatileOnVal(), sym.srcPos)
1007-
1007+
10081008
/** Check that unary method definition do not receive parameters.
10091009
* They can only receive inferred parameters such as type parameters and implicit parameters.
10101010
*/

tests/neg/i19731.check

+27
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

+17
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)