Skip to content

Commit 5d6a454

Browse files
committed
Handle TypeArgRefs in UserfacingPrinter
1 parent 369eae1 commit 5d6a454

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

repl/src/dotty/tools/repl/UserFacingPrinter.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import dotc.printing.{ GlobalPrec, DotPrec, Printer, PlainPrinter }
2121
import dotc.typer.Implicits.SearchResult
2222
import dotc.typer.ImportInfo
2323

24+
// TODO: Avoid code duplication between userfacing and refined printers
2425
class UserFacingPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
2526

2627
private def panic(msg: String): Nothing = throw new AssertionError(msg)
@@ -92,7 +93,7 @@ class UserFacingPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
9293
case tp: TypeAlias => toText(tp.underlying)
9394
case ExprType(result) => ":" ~~ toText(result)
9495
case TypeBounds(lo, hi) =>
95-
{ if (lo != defn.NothingType) toText(lo) ~~ ">: _" else Str("_") } ~~
96+
{ if (lo != defn.NothingType) toText(lo) ~~ ">: _" else Str("_") } ~~ // TODO: that's different from how args are written in source!
9697
{ if (hi != defn.AnyType) "<:" ~~ toText(hi) else Text() }
9798
case tp: TypeRef => tp.info match {
9899
case TypeAlias(alias) => toText(alias)
@@ -116,19 +117,28 @@ class UserFacingPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
116117
}
117118
}
118119
case AnyAppliedType(tycon, args) => {
120+
def argText(tp: Type) =
121+
toText {
122+
tp match {
123+
case tp: TypeArgRef => tp.underlying
124+
case _ => tp
125+
}
126+
}
119127
def toTextInfixType(tycon: Type, args: List[Type]): Text = {
120128
// TODO: blatant copy from `RefinedPrinter`
121129
val l :: r :: Nil = args
122130
val isRightAssoc = tycon.typeSymbol.name.endsWith(":")
123-
val leftArg = if (isRightAssoc && l.isInfixType) "(" ~ toText(l) ~ ")" else toText(l)
124-
val rightArg = if (!isRightAssoc && r.isInfixType) "(" ~ toText(r) ~ ")" else toText(r)
131+
val leftArg = if (isRightAssoc && l.isInfixType) "(" ~ argText(l) ~ ")" else argText(l)
132+
val rightArg = if (!isRightAssoc && r.isInfixType) "(" ~ argText(r) ~ ")" else argText(r)
125133
leftArg ~~ atPrec(DotPrec) { tycon.toText(this) } ~~ rightArg
126134
}
127135
if (tp.isInfixType) toTextInfixType(tycon, args)
128136
else {
129-
toText(tycon) ~ "[" ~ Fluid(args.reverse.map(toText).intersperse(Str(", "))) ~ "]"
137+
toText(tycon) ~ "[" ~ Fluid(args.reverse.map(argText).intersperse(Str(", "))) ~ "]"
130138
}
131139
}
140+
case tp: TypeArgRef =>
141+
super.toText(tp)
132142
case tp: ClassInfo => {
133143
if (wellKnownPkg(tp.cls.owner))
134144
nameString(tp.cls.name)

0 commit comments

Comments
 (0)