diff --git a/compiler/src/dotty/tools/dotc/reporting/DidYouMean.scala b/compiler/src/dotty/tools/dotc/reporting/DidYouMean.scala index 04b9b518fd5e..14e5e7798e05 100644 --- a/compiler/src/dotty/tools/dotc/reporting/DidYouMean.scala +++ b/compiler/src/dotty/tools/dotc/reporting/DidYouMean.scala @@ -149,7 +149,7 @@ object DidYouMean: if d != 0 || b.sym.is(ModuleClass) => // Avoid repeating the same name in "did you mean" if qualifies(b) then def hint(b: Binding) = prefix ++ showName(b.name, b.sym) - val alts = alternatives(d, rest).map(hint).take(3) + val alts = alternatives(d, rest).filter(_.name != b.name).map(hint).take(3).distinct val suffix = if alts.isEmpty then "" else alts.mkString(" or perhaps ", " or ", "?") s" - did you mean ${hint(b)}?$suffix" else diff --git a/tests/neg/i19958.check b/tests/neg/i19958.check new file mode 100644 index 000000000000..dbe1ddf682fd --- /dev/null +++ b/tests/neg/i19958.check @@ -0,0 +1,8 @@ +-- [E008] Not Found Error: tests/neg/i19958.scala:1:21 ----------------------------------------------------------------- +1 |val b = new Object().unit // error + | ^^^^^^^^^^^^^^^^^ + | value unit is not a member of Object - did you mean Object.wait? +-- [E008] Not Found Error: tests/neg/i19958.scala:10:10 ---------------------------------------------------------------- +10 |val d = c.unit // error + | ^^^^^^ + | value unit is not a member of C - did you mean c.blit? or perhaps c.wait? diff --git a/tests/neg/i19958.scala b/tests/neg/i19958.scala new file mode 100644 index 000000000000..eba89d969b63 --- /dev/null +++ b/tests/neg/i19958.scala @@ -0,0 +1,11 @@ +val b = new Object().unit // error + +abstract class C: + def wait: Unit + def wait(x: Int): Unit + def blit: Unit + def blit(x: Int): Unit + +val c: C = ??? +val d = c.unit // error +