Skip to content

Commit 1268474

Browse files
authored
Merge pull request #6735 from dotty-staging/fix-#6724
Fix #6724: Don't suggest types for terms and vice versa
2 parents 49c4a12 + 305cd72 commit 1268474

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,12 @@ object messages {
315315
val msg: String = {
316316
import core.Flags._
317317
val maxDist = 3
318-
val decls = site.decls.toList.flatMap { sym =>
319-
if (sym.flagsUNSAFE.isOneOf(Synthetic | PrivateLocal) || sym.isConstructor) Nil
320-
else List((sym.name.show, sym))
321-
}
318+
val decls = site.decls.toList
319+
.filter(_.isType == name.isTypeName)
320+
.flatMap { sym =>
321+
if (sym.flagsUNSAFE.isOneOf(Synthetic | PrivateLocal) || sym.isConstructor) Nil
322+
else List((sym.name.show, sym))
323+
}
322324

323325
// Calculate Levenshtein distance
324326
def distance(n1: Iterable[_], n2: Iterable[_]) =
@@ -358,7 +360,8 @@ object messages {
358360
}
359361

360362
val closeMember = closest match {
361-
case (n, sym) :: Nil => s" - did you mean $siteName.$n?"
363+
case (n, sym) :: Nil =>
364+
s" - did you mean $siteName.$n?"
362365
case Nil => ""
363366
case _ => assert(
364367
false,

compiler/test-resources/repl/importFromObj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ val res0: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3)
1414
scala> import util.foo
1515
1 | import util.foo
1616
| ^^^
17-
| value foo is not a member of util - did you mean util.Left?
17+
| value foo is not a member of util - did you mean util.Try?
1818
scala> import util.foo.bar
1919
1 | import util.foo.bar
2020
| ^^^^^^^^
21-
| value foo is not a member of util - did you mean util.Left?
21+
| value foo is not a member of util - did you mean util.Try?

tests/neg/i6724.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- [E008] Member Not Found Error: tests/neg/i6724.scala:7:17 -----------------------------------------------------------
2+
7 | def f(foo: Foo.Baz): Foo[_] = foo // error
3+
| ^^^^^^^
4+
| type Baz is not a member of object Foo - did you mean Foo.Bar?

tests/neg/i6724.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
enum Foo[T] {
2+
case Bar(s: String)
3+
case Baz extends Foo[Int]
4+
}
5+
6+
object Main {
7+
def f(foo: Foo.Baz): Foo[_] = foo // error
8+
}

0 commit comments

Comments
 (0)