Skip to content

Commit

Permalink
Avoid repetitions in name hints
Browse files Browse the repository at this point in the history
Fixes #19958

[Cherry-picked 572d6b1]
  • Loading branch information
odersky authored and WojciechMazur committed Jul 3, 2024
1 parent ac72874 commit 513c42d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/reporting/DidYouMean.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i19958.check
Original file line number Diff line number Diff line change
@@ -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?
11 changes: 11 additions & 0 deletions tests/neg/i19958.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 513c42d

Please sign in to comment.