Skip to content

Commit

Permalink
Improve error reporting for missing members
Browse files Browse the repository at this point in the history
Co-Authored-By: valentin2.schneeberger@gmail.com
Co-Authored-By: sana.carlo@gmail.com
Co-Authored-By: mehdi.ala03@gmail.com
  • Loading branch information
hamzaremmal committed Feb 27, 2024
1 parent 7f410aa commit 333c068
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,9 @@ object RefChecks {

val missingMethods = grouped.toList flatMap {
case (name, syms) =>
val withoutSetters = syms filterNot (_.isSetter)
if (withoutSetters.nonEmpty) withoutSetters else syms
syms.filterConserve(! _.isSetter)
.groupBy(_.signature) // Avoid duplication for similar definitions (#19731)
.map(f => f._2.head) // _1: Closest undefined method to the scope
}

def stubImplementations: List[String] = {
Expand All @@ -666,7 +667,7 @@ object RefChecks {

if (regrouped.tail.isEmpty)
membersStrings(regrouped.head._2)
else (regrouped.sortBy("" + _._1.name) flatMap {
else (regrouped.sortBy(_._1.name.toString()) flatMap {
case (owner, members) =>
("// Members declared in " + owner.fullName) +: membersStrings(members) :+ ""
}).init
Expand All @@ -685,7 +686,7 @@ object RefChecks {
return
}

for (member <- missing) {
for (member <- missingMethods) {
def showDclAndLocation(sym: Symbol) =
s"${sym.showDcl} in ${sym.owner.showLocated}"
def undefined(msg: String) =
Expand Down
27 changes: 27 additions & 0 deletions tests/neg/i19731.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- Error: tests/neg/i19731.scala:4:6 -----------------------------------------------------------------------------------
4 |class F1 extends Foo: // error
| ^
| class F1 needs to be abstract, since def foo(): Unit in class F1 is not defined
-- Error: tests/neg/i19731.scala:7:6 -----------------------------------------------------------------------------------
7 |class F2 extends Foo: // error
| ^
| class F2 needs to be abstract, since:
| it has 2 unimplemented members.
| /** As seen from class F2, the missing signatures are as follows.
| * For convenience, these are usable as stub implementations.
| */
| def foo(x: Int): Unit = ???
| def foo(): Unit = ???
-- Error: tests/neg/i19731.scala:16:6 ----------------------------------------------------------------------------------
16 |class B1 extends Bar: // error
| ^
| class B1 needs to be abstract, since:
| it has 2 unimplemented members.
| /** As seen from class B1, the missing signatures are as follows.
| * For convenience, these are usable as stub implementations.
| */
| // Members declared in B1
| def foo(x: Int): Unit = ???
|
| // Members declared in Bar
| def foo(): Unit = ???
17 changes: 17 additions & 0 deletions tests/neg/i19731.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
trait Foo:
def foo(): Unit

class F1 extends Foo: // error
def foo(): Unit

class F2 extends Foo: // error
def foo(): Unit
def foo(x: Int): Unit


trait Bar:
def foo(): Unit
def foo(x: Int): Unit

class B1 extends Bar: // error
def foo(x: Int): Unit

0 comments on commit 333c068

Please sign in to comment.