Skip to content

Commit 7107085

Browse files
committed
Don't disambiguate aliases
Don't disambiguate in situations like Predef.String vs java.lang.String where one Symbol is an alias of another with the same name. Also, fix reviewer comments wrt comments and unused defs.
1 parent 4a0858f commit 7107085

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ object Formatting {
5858
}
5959
}
6060

61-
/** The d string interpolator works like the i string interpolator, but marks nonsensical errors
61+
/** The `em` string interpolator works like the `i` string interpolator, but marks nonsensical errors
6262
* using `<nonsensical>...</nonsensical>` tags.
6363
* Note: Instead of these tags, it would be nicer to return a data structure containing the message string
6464
* and a boolean indicating whether the message is sensical, but then we cannot use string operations
65-
* like concatenation, stripMargin etc on the values returned by d"...", and in the current error
65+
* like concatenation, stripMargin etc on the values returned by em"...", and in the current error
6666
* message composition methods, this is crucial.
6767
*/
6868
class ErrorMessageFormatter(sc: StringContext) extends StringFormatter(sc) {
@@ -85,8 +85,15 @@ object Formatting {
8585

8686
override def default(key: String) = Nil
8787

88-
def record(str: String, entry: Recorded): String = {
89-
var alts = apply(str).dropWhile(entry ne _)
88+
def record(str: String, entry: Recorded)(implicit ctx: Context): String = {
89+
def followAlias(e1: Recorded): Recorded = e1 match {
90+
case e1: Symbol if e1.isAliasType =>
91+
val underlying = e1.typeRef.underlyingClassRef(refinementOK = false).typeSymbol
92+
if (underlying.name == e1.name) underlying else e1
93+
case _ => e1
94+
}
95+
lazy val dealiased = followAlias(entry)
96+
var alts = apply(str).dropWhile(alt => dealiased ne followAlias(alt))
9097
if (alts.isEmpty) {
9198
alts = entry :: apply(str)
9299
update(str, alts)
@@ -135,13 +142,6 @@ object Formatting {
135142
case param: PolyParam =>
136143
s"is a type variable${addendum("constraint", ctx.typeComparer.bounds(param))}"
137144
case sym: Symbol =>
138-
val ownerStr =
139-
if (!sym.exists) ""
140-
else {
141-
var owner = sym.effectiveOwner
142-
if (owner.isLocalDummy) i" locally defined in ${owner.owner}"
143-
else i" in $owner"
144-
}
145145
s"is a ${ctx.printer.kindString(sym)}${sym.showExtendedLocation}${addendum("bounds", sym.info)}"
146146
}
147147
}

0 commit comments

Comments
 (0)