Skip to content

Commit b6f5c6a

Browse files
committed
Better homogenization.
Needed for next commit. Also homogenize types used in prefixes, and never drop "scala.", "Predef." in homogenized view.
1 parent 52d6ac3 commit b6f5c6a

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ class PlainPrinter(_ctx: Context) extends Printer {
4040
def homogenize(tp: Type): Type =
4141
if (homogenizedView)
4242
tp match {
43-
case tp: TypeVar if tp.isInstantiated => homogenize(tp.instanceOpt)
44-
case AndType(tp1, tp2) => homogenize(tp1) & homogenize(tp2)
45-
case OrType(tp1, tp2) => homogenize(tp1) | homogenize(tp2)
43+
case tp: ThisType if tp.cls.is(Package) && !tp.cls.isEffectiveRoot =>
44+
ctx.requiredPackage(tp.cls.fullName).termRef
45+
case tp: TypeVar if tp.isInstantiated =>
46+
homogenize(tp.instanceOpt)
47+
case AndType(tp1, tp2) =>
48+
homogenize(tp1) & homogenize(tp2)
49+
case OrType(tp1, tp2) =>
50+
homogenize(tp1) | homogenize(tp2)
4651
case _ =>
4752
val tp1 = tp.simplifyApply
4853
if (tp1 eq tp) tp else homogenize(tp1)
@@ -230,10 +235,10 @@ class PlainPrinter(_ctx: Context) extends Printer {
230235

231236
/** The string representation of this type used as a prefix */
232237
protected def toTextPrefix(tp: Type): Text = controlled {
233-
tp match {
238+
homogenize(tp) match {
234239
case NoPrefix => ""
235240
case tp: SingletonType => toTextRef(tp) ~ "."
236-
case _ => trimPrefix(toTextLocal(tp)) ~ "#"
241+
case tp => trimPrefix(toTextLocal(tp)) ~ "#"
237242
}
238243
}
239244

@@ -253,7 +258,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
253258

254259
/** String representation of a definition's type following its name */
255260
protected def toTextRHS(tp: Type): Text = controlled {
256-
tp match {
261+
homogenize(tp) match {
257262
case tp @ TypeBounds(lo, hi) =>
258263
if (lo eq hi) {
259264
val eql =
@@ -280,7 +285,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
280285
else dclsText(trueDecls)
281286
tparamsText ~ " extends " ~ toTextParents(tp.parents) ~ "{" ~ selfText ~ declsText ~
282287
"} at " ~ preText
283-
case _ =>
288+
case tp =>
284289
": " ~ toTextGlobal(tp)
285290
}
286291
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
6363
}
6464

6565
override def toTextPrefix(tp: Type): Text = controlled {
66-
def isOmittable(sym: Symbol) = isOmittablePrefix(sym) && !ctx.settings.verbose.value
66+
def isOmittable(sym: Symbol) =
67+
if (ctx.settings.verbose.value) false
68+
else if (homogenizedView) isEmptyPrefix(sym) // drop <root> and anonymous classes, but not scala, Predef.
69+
else isOmittablePrefix(sym)
6770
tp match {
6871
case tp: ThisType =>
6972
if (isOmittable(tp.cls)) return ""

0 commit comments

Comments
 (0)