Skip to content

Commit 45d3027

Browse files
committed
Print dependent function types correctly in RefinedPrinter
1 parent 1342a5e commit 45d3027

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,17 @@ class PlainPrinter(_ctx: Context) extends Printer {
184184
case NoPrefix =>
185185
"<noprefix>"
186186
case tp: MethodType =>
187-
def paramText(name: TermName, tp: Type) = toText(name) ~ ": " ~ toText(tp)
188187
changePrec(GlobalPrec) {
189-
(if (tp.isImplicitMethod) "(implicit " else "(") ~
190-
Text((tp.paramNames, tp.paramInfos).zipped map paramText, ", ") ~
188+
(if (tp.isImplicitMethod) "(implicit " else "(") ~ paramsText(tp) ~
191189
(if (tp.resultType.isInstanceOf[MethodType]) ")" else "): ") ~
192190
toText(tp.resultType)
193191
}
194192
case tp: ExprType =>
195193
changePrec(GlobalPrec) { "=> " ~ toText(tp.resultType) }
196194
case tp: TypeLambda =>
197-
def paramText(name: Name, bounds: TypeBounds): Text = name.unexpandedName.toString ~ toText(bounds)
198195
changePrec(GlobalPrec) {
199-
"[" ~ Text((tp.paramNames, tp.paramInfos).zipped.map(paramText), ", ") ~
200-
"]" ~ lambdaHash(tp) ~ (" => " provided !tp.resultType.isInstanceOf[MethodType]) ~
196+
"[" ~ paramsText(tp) ~ "]" ~ lambdaHash(tp) ~
197+
(" => " provided !tp.resultType.isInstanceOf[MethodType]) ~
201198
toTextGlobal(tp.resultType)
202199
}
203200
case AnnotatedType(tpe, annot) =>
@@ -223,6 +220,11 @@ class PlainPrinter(_ctx: Context) extends Printer {
223220
}
224221
}.close
225222

223+
protected def paramsText(tp: LambdaType): Text = {
224+
def paramText(name: Name, tp: Type) = toText(name) ~ toTextRHS(tp)
225+
Text((tp.paramNames, tp.paramInfos).zipped.map(paramText), ", ")
226+
}
227+
226228
protected def ParamRefNameString(name: Name): String = name.toString
227229

228230
protected def ParamRefNameString(param: ParamRef): String =

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
113113
override def toText(tp: Type): Text = controlled {
114114
def toTextTuple(args: List[Type]): Text =
115115
"(" ~ Text(args.map(argText), ", ") ~ ")"
116+
116117
def toTextFunction(args: List[Type], isImplicit: Boolean): Text =
117118
changePrec(GlobalPrec) {
118119
val argStr: Text =
@@ -123,6 +124,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
123124
("implicit " provided isImplicit) ~ argStr ~ " => " ~ argText(args.last)
124125
}
125126

127+
def toTextDependentFunction(appType: MethodType): Text = {
128+
("implicit " provided appType.isImplicitMethod) ~
129+
"(" ~ paramsText(appType) ~ ") => " ~ toText(appType.resultType)
130+
}
131+
126132
def isInfixType(tp: Type): Boolean = tp match {
127133
case AppliedType(tycon, args) =>
128134
args.length == 2 &&
@@ -155,6 +161,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
155161
if (isInfixType(tp)) return toTextInfixType(tycon, args)
156162
case EtaExpansion(tycon) =>
157163
return toText(tycon)
164+
case tp: RefinedType if defn.isFunctionType(tp) =>
165+
return toTextDependentFunction(tp.refinedInfo.asInstanceOf[MethodType])
158166
case tp: TypeRef =>
159167
if (tp.symbol.isAnonymousClass && !ctx.settings.uniqid.value)
160168
return toText(tp.info)

0 commit comments

Comments
 (0)