Skip to content

Commit 48039dd

Browse files
Backport "Fix type mismatch error confusion between types with same simple name " to LTS (#20795)
Backports #19204 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents faa5163 + 8f59a2c commit 48039dd

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
177177
"<overloaded " ~ toTextRef(tp) ~ ">"
178178
case tp: TypeRef =>
179179
if (printWithoutPrefix.contains(tp.symbol))
180-
toText(tp.name)
180+
selectionString(tp)
181181
else
182182
toTextPrefixOf(tp) ~ selectionString(tp)
183183
case tp: TermParamRef =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ object Message:
8181
def followAlias(e1: Recorded): Recorded = e1 match {
8282
case e1: Symbol if e1.isAliasType =>
8383
val underlying = e1.typeRef.underlyingClassRef(refinementOK = false).typeSymbol
84-
if (underlying.name == e1.name) underlying else e1
84+
if (underlying.name == e1.name) underlying else e1.namedType.dealias.typeSymbol
8585
case _ => e1
8686
}
8787
val key = SeenKey(str, isType)

tests/neg/i18678b.check

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i18678b.scala:3:16 ------------------------------------------------------------
2+
3 |def s: String = "" // error
3+
| ^^
4+
| Found: ("" : String)
5+
| Required: String²
6+
|
7+
| where: String is a class in package java.lang
8+
| String² is a class in the empty package
9+
|
10+
| longer explanation available when compiling with `-explain`

tests/neg/i18678b.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class String
2+
3+
def s: String = "" // error

0 commit comments

Comments
 (0)