Skip to content
Open
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
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/DidYouMean.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import core.*
import Contexts.*
import Decorators.*, Symbols.*, Names.*, Types.*, Flags.*
import typer.ProtoTypes.SelectionProto
import collection.mutable

/** A utility object to support "did you mean" hinting */
object DidYouMean:
Expand Down Expand Up @@ -46,6 +47,8 @@ object DidYouMean:
then ctx.outer
else nextInteresting(ctx.outer)

val ignoredRootImports = mutable.Set.empty[Symbol]

def recur()(using Context): Unit =
if ctx eq NoContext then
() // done
Expand All @@ -54,7 +57,7 @@ object DidYouMean:
if imp.isRootImport && !rootImportOK then
() // done
else imp.importSym.info match
case ImportType(expr) =>
case ImportType(expr) if !ignoredRootImports.contains(expr.symbol) =>
val candidates = memberCandidates(expr.tpe, isType, isApplied)
if imp.isWildcardImport then
for cand <- candidates if !imp.excluded.contains(cand.name.toTermName) do
Expand All @@ -67,6 +70,8 @@ object DidYouMean:
else if !sel.isUnimport then
for cand <- candidates if cand.name.toTermName.show == selStr do
acc += Binding(sel.rename.likeSpaced(cand.name), cand, expr.tpe)
if imp.unimported.exists then
ignoredRootImports += imp.unimported
case _ =>
recur()(using nextInteresting(ctx))
else
Expand Down
24 changes: 24 additions & 0 deletions tests/neg/i24995.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- [E006] Not Found Error: tests/neg/i24995.scala:2:7 ------------------------------------------------------------------
2 |val x: Mop[Int, Int] = Mop() // error // error
| ^^^
| Not found: type Mop - did you mean Map?
|
| longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i24995.scala:2:23 -----------------------------------------------------------------
2 |val x: Mop[Int, Int] = Mop() // error // error
| ^^^
| Not found: Mop - did you mean Map?
|
| longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i24995.scala:6:9 ------------------------------------------------------------------
6 | val y: Mop[Int, Int] = Mop() // error // error
| ^^^
| Not found: type Mop
|
| longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i24995.scala:6:25 -----------------------------------------------------------------
6 | val y: Mop[Int, Int] = Mop() // error // error
| ^^^
| Not found: Mop
|
| longer explanation available when compiling with `-explain`
6 changes: 6 additions & 0 deletions tests/neg/i24995.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

val x: Mop[Int, Int] = Mop() // error // error

def f() =
import Predef.{Map as _, *}
val y: Mop[Int, Int] = Mop() // error // error
2 changes: 1 addition & 1 deletion tests/neg/yimports-order.check
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- [E006] Not Found Error: tests/neg/yimports-order.scala:9:16 ---------------------------------------------------------
9 | def f() = Map("hello" -> "world") // error // error
| ^^^
| Expected a term, but found a type: Map
| Not found: Map
|
| longer explanation available when compiling with `-explain`
-- [E008] Not Found Error: tests/neg/yimports-order.scala:9:28 ---------------------------------------------------------
Expand Down
Loading