Skip to content

Commit

Permalink
Improve type mismatch errors with fully qualified names for types wit…
Browse files Browse the repository at this point in the history
…hin the scala package

Co-authored-by: Nicolas Stucki <[email protected]>
  • Loading branch information
ausmarton and nicolasstucki committed Dec 5, 2023
1 parent a3854cb commit 792293d
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 792293d

Please sign in to comment.