Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type mismatch error confusion between types with same simple name #19204

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading