Skip to content

Commit

Permalink
Backport "Avoid repetitions in name hints" to LTS (#20998)
Browse files Browse the repository at this point in the history
Backports #19975 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jul 4, 2024
2 parents 03adfb9 + 513c42d commit df98f58
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 df98f58

Please sign in to comment.