Skip to content

Commit

Permalink
Fix type mismatch error confusion between types with same simple name (
Browse files Browse the repository at this point in the history
…#19204)

Fixes #18678 

Accidentally closed the original PR for this here: #19088
  • Loading branch information
nicolasstucki authored Dec 11, 2023
2 parents fdd06ce + 38bf775 commit efae7bb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
"<overloaded " ~ toTextRef(tp) ~ ">"
case tp: TypeRef =>
if (printWithoutPrefix.contains(tp.symbol))
toText(tp.name)
selectionString(tp)
else
toTextPrefixOf(tp) ~ selectionString(tp)
case tp: TermParamRef =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/reporting/Message.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object Message:
def followAlias(e1: Recorded): Recorded = e1 match {
case e1: Symbol if e1.isAliasType =>
val underlying = e1.typeRef.underlyingClassRef(refinementOK = false).typeSymbol
if (underlying.name == e1.name) underlying else e1
if (underlying.name == e1.name) underlying else e1.namedType.dealias.typeSymbol
case _ => e1
}
val key = SeenKey(str, isType)
Expand Down
10 changes: 10 additions & 0 deletions tests/neg/i18678b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- [E007] Type Mismatch Error: tests/neg/i18678b.scala:3:16 ------------------------------------------------------------
3 |def s: String = "" // error
| ^^
| Found: ("" : String)
| Required: String²
|
| where: String is a class in package java.lang
| String² is a class in the empty package
|
| longer explanation available when compiling with `-explain`
3 changes: 3 additions & 0 deletions tests/neg/i18678b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class String

def s: String = "" // error

0 comments on commit efae7bb

Please sign in to comment.