From 50937d31c32a40096e6cf4c8e9aae2f9b980d5a1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 24 Jun 2019 14:41:18 +0200 Subject: [PATCH 1/2] 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. --- .../tools/dotc/reporting/diagnostic/messages.scala | 13 ++++++++----- tests/neg/i6724.scala | 8 ++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 tests/neg/i6724.scala diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 833177493b7c..675365864c98 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -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[_]) = @@ -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, diff --git a/tests/neg/i6724.scala b/tests/neg/i6724.scala new file mode 100644 index 000000000000..d9be5cbca16f --- /dev/null +++ b/tests/neg/i6724.scala @@ -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 +} From 305cd722a6e341410d0b6a0e5a34e90c05866416 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 24 Jun 2019 15:22:13 +0200 Subject: [PATCH 2/2] Fix tests --- compiler/test-resources/repl/importFromObj | 4 ++-- tests/neg/i6724.check | 4 ++++ tests/neg/i6724.scala | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 tests/neg/i6724.check diff --git a/compiler/test-resources/repl/importFromObj b/compiler/test-resources/repl/importFromObj index 351c27fa2f5b..6dca6bf27462 100644 --- a/compiler/test-resources/repl/importFromObj +++ b/compiler/test-resources/repl/importFromObj @@ -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? 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? diff --git a/tests/neg/i6724.check b/tests/neg/i6724.check new file mode 100644 index 000000000000..f3665b8b2f79 --- /dev/null +++ b/tests/neg/i6724.check @@ -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? diff --git a/tests/neg/i6724.scala b/tests/neg/i6724.scala index d9be5cbca16f..7cb4d8eddbfb 100644 --- a/tests/neg/i6724.scala +++ b/tests/neg/i6724.scala @@ -4,5 +4,5 @@ enum Foo[T] { } object Main { - def f(foo: Foo.Baz): Foo[_] = foo + def f(foo: Foo.Baz): Foo[_] = foo // error }