Skip to content

Fix #6724: Don't suggest types for terms and vice versa #6735

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 2 commits into from
Jun 24, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,12 @@ object messages {
val msg: String = {
import core.Flags._
val maxDist = 3
val decls = site.decls.toList.flatMap { sym =>
if (sym.flagsUNSAFE.isOneOf(Synthetic | PrivateLocal) || sym.isConstructor) Nil
else List((sym.name.show, sym))
}
val decls = site.decls.toList
.filter(_.isType == name.isTypeName)
.flatMap { sym =>
if (sym.flagsUNSAFE.isOneOf(Synthetic | PrivateLocal) || sym.isConstructor) Nil
else List((sym.name.show, sym))
}

// Calculate Levenshtein distance
def distance(n1: Iterable[_], n2: Iterable[_]) =
Expand Down Expand Up @@ -358,7 +360,8 @@ object messages {
}

val closeMember = closest match {
case (n, sym) :: Nil => s" - did you mean $siteName.$n?"
case (n, sym) :: Nil =>
s" - did you mean $siteName.$n?"
case Nil => ""
case _ => assert(
false,
Expand Down
4 changes: 2 additions & 2 deletions compiler/test-resources/repl/importFromObj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ val res0: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3)
scala> import util.foo
1 | import util.foo
| ^^^
| value foo is not a member of util - did you mean util.Left?
| value foo is not a member of util - did you mean util.Try?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain this one to me? import util.Left is invalid? Or did it change because Try has a higher priority on the list of suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or did it change because Try has a higher priority on the list of suggestions?

Something like that yeah. Ideally it should just not offer any suggestion at all when there's nothing close to what the user has written.

scala> import util.foo.bar
1 | import util.foo.bar
| ^^^^^^^^
| value foo is not a member of util - did you mean util.Left?
| value foo is not a member of util - did you mean util.Try?
4 changes: 4 additions & 0 deletions tests/neg/i6724.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- [E008] Member Not Found Error: tests/neg/i6724.scala:7:17 -----------------------------------------------------------
7 | def f(foo: Foo.Baz): Foo[_] = foo // error
| ^^^^^^^
| type Baz is not a member of object Foo - did you mean Foo.Bar?
8 changes: 8 additions & 0 deletions tests/neg/i6724.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
enum Foo[T] {
case Bar(s: String)
case Baz extends Foo[Int]
}

object Main {
def f(foo: Foo.Baz): Foo[_] = foo // error
}