Skip to content

Commit 4073d24

Browse files
committed
fix #13320 add .type to modules in messages
co-authored by: Anatolii Kmetiuk anatoliykmetyuk@gmail.com
1 parent 01be968 commit 4073d24

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,12 @@ import transform.SymUtils._
280280
val (foundStr, expectedStr) = Formatting.typeDiff(found2, expected2)(using printCtx)
281281
s"""|Found: $foundStr
282282
|Required: $expectedStr""".stripMargin
283-
+ whereSuffix + postScript
283+
+ whereSuffix + postScript
284284

285-
override def explain =
285+
override def explain =
286286
val treeStr = inTree.map(x => s"\nTree: ${x.show}").getOrElse("")
287287
treeStr + "\n" + super.explain
288-
288+
289289

290290
end TypeMismatch
291291

@@ -300,14 +300,14 @@ import transform.SymUtils._
300300

301301
// The names of all non-synthetic, non-private members of `site`
302302
// that are of the same type/term kind as the missing member.
303-
def candidates: Set[String] =
303+
def candidates: Set[Symbol] =
304304
for
305305
bc <- site.widen.baseClasses.toSet
306306
sym <- bc.info.decls.filter(sym =>
307307
sym.isType == name.isTypeName
308308
&& !sym.isConstructor
309309
&& !sym.flagsUNSAFE.isOneOf(Synthetic | Private))
310-
yield sym.name.show
310+
yield sym
311311

312312
// Calculate Levenshtein distance
313313
def distance(s1: String, s2: String): Int =
@@ -325,11 +325,11 @@ import transform.SymUtils._
325325

326326
// A list of possible candidate strings with their Levenstein distances
327327
// to the name of the missing member
328-
def closest: List[(Int, String)] = candidates
328+
def closest: List[(Int, Symbol)] = candidates
329329
.toList
330-
.map(n => (distance(n, missing), n))
331-
.filter((d, n) => d <= maxDist && d < missing.length && d < n.length)
332-
.sorted // sort by distance first, alphabetically second
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
333333

334334
val enumClause =
335335
if ((name eq nme.values) || (name eq nme.valueOf)) && site.classSymbol.companionClass.isEnumClass then
@@ -352,7 +352,11 @@ import transform.SymUtils._
352352
val siteName = site match
353353
case site: NamedType => site.name.show
354354
case site => i"$site"
355-
s" - did you mean $siteName.$n?$enumClause"
355+
val showName =
356+
// 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
359+
s" - did you mean $siteName.$showName?$enumClause"
356360
case Nil => prefixEnumClause("")
357361

358362
ex"$selected $name is not a member of ${site.widen}$finalAddendum"

0 commit comments

Comments
 (0)