Skip to content

Commit e0139bf

Browse files
committed
Fix #3025: remove duplicated logic from UserFacingPrinter
1 parent 94bdcf5 commit e0139bf

File tree

2 files changed

+7
-55
lines changed

2 files changed

+7
-55
lines changed

compiler/src/dotty/tools/dotc/printing/UserFacingPrinter.scala

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
package dotty.tools.dotc
22
package printing
33

4-
import ast.Trees.{ Untyped, Tree }
54
import core._
6-
import Annotations.Annotation
7-
import Constants.Constant
8-
import Contexts.Context
9-
import Denotations.{ Denotation, MultiDenotation, SingleDenotation }
10-
import Flags._
11-
import TypeApplications.{ AppliedType, EtaExpansion }
12-
import Names._
13-
import NameOps._
14-
import StdNames._
15-
import Decorators._
16-
import Scopes.Scope
17-
import Symbols.{ Symbol, ClassSymbol, defn }
18-
import SymDenotations.NoDenotation
19-
import Types._
20-
import Texts._
5+
import Constants.Constant, Contexts.Context, Denotations._, Flags._, Names._
6+
import NameOps._, StdNames._, Decorators._, Scopes.Scope, Types._, Texts._
7+
import SymDenotations.NoDenotation, Symbols.{ Symbol, ClassSymbol, defn }
218
import typer.Implicits.SearchResult
229
import typer.ImportInfo
2310

2411
class UserFacingPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
2512

26-
private def panic(msg: String): Nothing = throw new AssertionError(msg)
27-
2813
private[this] def getPkgCls(path: String) =
2914
_ctx.requiredPackage(path).moduleClass.asClass
3015

@@ -45,7 +30,7 @@ class UserFacingPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
4530
def wellKnownPkg(pkgSym: Symbol) = standardPkg(pkgSym) || wrappedName(pkgSym)
4631

4732
override protected def keyString(sym: Symbol): String = {
48-
val flags = sym.flags
33+
val flags = sym.flagsUNSAFE
4934
if (flags is Package) ""
5035
else if (sym.isPackageObject) "package object"
5136
else if (flags.is(Module) && flags.is(Case)) "case object"
@@ -68,7 +53,7 @@ class UserFacingPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
6853
toText(sym) ~ {
6954
if (sym.is(Method)) toText(sym.info)
7055
else if (sym.isClass) ""
71-
else if (sym.isType && sym.info.isInstanceOf[TypeAlias]) " =" ~~ toText(sym.info)
56+
else if (sym.isType && sym.info.isInstanceOf[TypeAlias]) toText(sym.info)
7257
else if (sym.isType) ""
7358
else {
7459
":" ~~ toText(sym.info)
@@ -78,48 +63,17 @@ class UserFacingPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
7863
override def toText(const: Constant): Text = Str(const.value.toString)
7964

8065
override def toText(tp: Type): Text = tp match {
81-
case tp: AnnotatedType => toText(tp.tpe) ~~ toText(tp.annot)
8266
case tp: ConstantType => toText(tp.value)
83-
case tp: TypeAlias => toText(tp.underlying)
8467
case ExprType(result) => ":" ~~ toText(result)
85-
case TypeBounds(lo, hi) =>
86-
{ if (lo != defn.NothingType) toText(lo) ~~ ">: _" else Str("_") } ~~
87-
{ if (hi != defn.AnyType) "<:" ~~ toText(hi) else Text() }
8868
case tp: TypeRef => tp.info match {
8969
case TypeAlias(alias) => toText(alias)
9070
case _ => toText(tp.info)
9171
}
9272
case tp: ParamRef => {
93-
val name = tp.paramName.unexpandedName.invariantName.toString
73+
val name = ParamRefNameString(tp.paramName)
9474
if (tp.isInstanceOf[TermParamRef]) name ~ ".type"
9575
else name
9676
}
97-
case EtaExpansion(tycon) => toText(tycon)
98-
case PolyType(params, res) =>
99-
"[" ~ Fluid(params.map(tl => toText(tl.toArg)).intersperse(Str(", "))) ~ "]" ~ toText(res)
100-
case tp: MethodType => {
101-
def paramText(name: TermName, tp: Type) = toText(name) ~ ": " ~ toText(tp)
102-
changePrec(GlobalPrec) {
103-
(if (tp.isImplicit) "(implicit " else "(") ~
104-
Text((tp.paramNames, tp.paramInfos).zipped map paramText, ", ") ~
105-
(if (tp.resultType.isInstanceOf[MethodType]) ")" else "): ") ~
106-
toText(tp.resultType)
107-
}
108-
}
109-
case AppliedType(tycon, args) => {
110-
def toTextInfixType(tycon: Type, args: List[Type]): Text = {
111-
// TODO: blatant copy from `RefinedPrinter`
112-
val l :: r :: Nil = args
113-
val isRightAssoc = tycon.typeSymbol.name.endsWith(":")
114-
val leftArg = if (isRightAssoc && l.isInfixType) "(" ~ toText(l) ~ ")" else toText(l)
115-
val rightArg = if (!isRightAssoc && r.isInfixType) "(" ~ toText(r) ~ ")" else toText(r)
116-
leftArg ~~ atPrec(DotPrec) { tycon.toText(this) } ~~ rightArg
117-
}
118-
if (tp.isInfixType) toTextInfixType(tycon, args)
119-
else {
120-
toText(tycon) ~ "[" ~ Fluid(args.reverse.map(toText).intersperse(Str(", "))) ~ "]"
121-
}
122-
}
12377
case tp: ClassInfo => {
12478
if (wellKnownPkg(tp.cls.owner))
12579
nameString(tp.cls.name)

compiler/test-resources/repl/i2554

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ scala> import foo._
44
scala> implicit val shape: Shape[_ <: FlatShapeLevel, Int, Int, _] = null
55
implicit val shape: foo.Shape[_ <: foo.FlatShapeLevel, Int, Int, _] = null
66
scala> def hint = Shape.tuple2Shape(shape, shape)
7-
def hint: foo.Shape[foo.FlatShapeLevel, Tuple2[Int, Int], Tuple2[Int, Int],
8-
Tuple2
9-
[_, _]]
7+
def hint: foo.Shape[foo.FlatShapeLevel, (Int, Int), (Int, Int), ()]

0 commit comments

Comments
 (0)