Skip to content

Commit df98f58

Browse files
Backport "Avoid repetitions in name hints" to LTS (#20998)
Backports #19975 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 03adfb9 + 513c42d commit df98f58

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/reporting/DidYouMean.scala

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

Diff for: tests/neg/i19958.check

+8
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?

Diff for: tests/neg/i19958.scala

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