Skip to content

Commit 9b83580

Browse files
oderskyWojciechMazur
authored andcommitted
Avoid repetitions in name hints
Fixes #19958 [Cherry-picked 572d6b1]
1 parent 114292f commit 9b83580

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

compiler/src/dotty/tools/dotc/reporting/DidYouMean.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ object DidYouMean:
149149
if d != 0 || b.sym.is(ModuleClass) => // Avoid repeating the same name in "did you mean"
150150
if qualifies(b) then
151151
def hint(b: Binding) = prefix ++ showName(b.name, b.sym)
152-
val alts = alternatives(d, rest).map(hint).take(3)
152+
val alts = alternatives(d, rest).filter(_.name != b.name).map(hint).take(3).distinct
153153
val suffix = if alts.isEmpty then "" else alts.mkString(" or perhaps ", " or ", "?")
154154
s" - did you mean ${hint(b)}?$suffix"
155155
else

tests/neg/i19958.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- [E008] Not Found Error: tests/neg/i19958.scala:1:21 -----------------------------------------------------------------
2+
1 |val b = new Object().unit // error
3+
| ^^^^^^^^^^^^^^^^^
4+
| value unit is not a member of Object - did you mean Object.wait?
5+
-- [E008] Not Found Error: tests/neg/i19958.scala:10:10 ----------------------------------------------------------------
6+
10 |val d = c.unit // error
7+
| ^^^^^^
8+
| value unit is not a member of C - did you mean c.blit? or perhaps c.wait?

tests/neg/i19958.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
val b = new Object().unit // error
2+
3+
abstract class C:
4+
def wait: Unit
5+
def wait(x: Int): Unit
6+
def blit: Unit
7+
def blit(x: Int): Unit
8+
9+
val c: C = ???
10+
val d = c.unit // error
11+

0 commit comments

Comments
 (0)