Skip to content

Commit 50937d3

Browse files
committed
Fix #6724: Don't suggest types for terms and vice versa
Filter candidate definitions for member suggestions to be either types or terms, depending on the selection name.
1 parent b5a6963 commit 50937d3

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
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,

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

0 commit comments

Comments
 (0)