Skip to content

Commit 5400724

Browse files
add test, fix review comments
Co-authored-by: Michał Pałka <[email protected]>
1 parent 4073d24 commit 5400724

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ import transform.SymUtils._
298298
val maxDist = 3 // maximal number of differences to be considered for a hint
299299
val missing = name.show
300300

301-
// The names of all non-synthetic, non-private members of `site`
301+
// The symbols of all non-synthetic, non-private members of `site`
302302
// that are of the same type/term kind as the missing member.
303303
def candidates: Set[Symbol] =
304304
for
@@ -323,13 +323,13 @@ import transform.SymUtils._
323323
else (dist(j - 1)(i) min dist(j)(i - 1) min dist(j - 1)(i - 1)) + 1
324324
dist(s2.length)(s1.length)
325325

326-
// A list of possible candidate strings with their Levenstein distances
326+
// A list of possible candidate symbols with their Levenstein distances
327327
// to the name of the missing member
328328
def closest: List[(Int, Symbol)] = candidates
329329
.toList
330-
.map(n => (distance(n.name.show, missing), n))
331-
.filter((d, n) => d <= maxDist && d < missing.length && d < n.name.show.length)
332-
.sortBy((d, n) => (d, n.name.show)) // sort by distance first, alphabetically second
330+
.map(sym => (distance(sym.name.show, missing), sym))
331+
.filter((d, sym) => d <= maxDist && d < missing.length && d < sym.name.show.length)
332+
.sortBy((d, sym) => (d, sym.name.show)) // sort by distance first, alphabetically second
333333

334334
val enumClause =
335335
if ((name eq nme.values) || (name eq nme.valueOf)) && site.classSymbol.companionClass.isEnumClass then
@@ -348,14 +348,14 @@ import transform.SymUtils._
348348
val finalAddendum =
349349
if addendum.nonEmpty then prefixEnumClause(addendum)
350350
else closest match
351-
case (d, n) :: _ =>
351+
case (d, sym) :: _ =>
352352
val siteName = site match
353353
case site: NamedType => site.name.show
354354
case site => i"$site"
355355
val showName =
356356
// Add .type to the name if it is a module
357-
if n.isClass && n.is(Module) then s"${n.name.show}.type"
358-
else n.name.show
357+
if sym.is(ModuleClass) then s"${sym.name.show}.type"
358+
else sym.name.show
359359
s" - did you mean $siteName.$showName?$enumClause"
360360
case Nil => prefixEnumClause("")
361361

tests/neg/i13320.check

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- [E008] Not Found Error: tests/neg/i13320.scala:8:24 -----------------------------------------------------------------
2+
8 | type t = Option[Foo.Boo] // error
3+
| ^^^^^^^
4+
| type Boo is not a member of object Foo - did you mean Foo.Boo.type?
5+
-- [E008] Not Found Error: tests/neg/i13320.scala:4:11 -----------------------------------------------------------------
6+
4 |var x: Foo.Booo = Foo.Booo // error // error
7+
| ^^^^^^^^
8+
| type Booo is not a member of object Foo - did you mean Foo.Boo.type?
9+
-- [E008] Not Found Error: tests/neg/i13320.scala:4:22 -----------------------------------------------------------------
10+
4 |var x: Foo.Booo = Foo.Booo // error // error
11+
| ^^^^^^^^
12+
| value Booo is not a member of object Foo - did you mean Foo.Boo?

tests/neg/i13320.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Foo:
2+
case object Boo
3+
4+
var x: Foo.Booo = Foo.Booo // error // error
5+
6+
object Main:
7+
def main(args: Array[String]) =
8+
type t = Option[Foo.Boo] // error

0 commit comments

Comments
 (0)