Skip to content

Commit 1e753c3

Browse files
committed
Print dependent function types correctly in RefinedPrinter
1 parent 9106bf1 commit 1e753c3

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) =>
@@ -221,6 +218,11 @@ class PlainPrinter(_ctx: Context) extends Printer {
221218
}
222219
}.close
223220

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

226228
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
@@ -116,6 +116,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
116116
override def toText(tp: Type): Text = controlled {
117117
def toTextTuple(args: List[Type]): Text =
118118
"(" ~ Text(args.map(argText), ", ") ~ ")"
119+
119120
def toTextFunction(args: List[Type], isImplicit: Boolean): Text =
120121
changePrec(GlobalPrec) {
121122
val argStr: Text =
@@ -126,6 +127,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
126127
("implicit " provided isImplicit) ~ argStr ~ " => " ~ argText(args.last)
127128
}
128129

130+
def toTextDependentFunction(appType: MethodType): Text = {
131+
("implicit " provided appType.isImplicitMethod) ~
132+
"(" ~ paramsText(appType) ~ ") => " ~ toText(appType.resultType)
133+
}
134+
129135
def isInfixType(tp: Type): Boolean = tp match {
130136
case AppliedType(tycon, args) =>
131137
args.length == 2 &&
@@ -158,6 +164,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
158164
if (isInfixType(tp)) return toTextInfixType(tycon, args)
159165
case EtaExpansion(tycon) =>
160166
return toText(tycon)
167+
case tp: RefinedType if defn.isFunctionType(tp) =>
168+
return toTextDependentFunction(tp.refinedInfo.asInstanceOf[MethodType])
161169
case tp: TypeRef =>
162170
if (tp.symbol.isAnonymousClass && !ctx.settings.uniqid.value)
163171
return toText(tp.info)

0 commit comments

Comments
 (0)