Skip to content

Avoid repetitions in name hints #19975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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