Skip to content

Commit 3817733

Browse files
committed
Fix #4068 properly
`argText` will never add parentheses around its output, which makes sense for arguments of type constructors: if we're printing `Foo[T1, T2]` we never need parens around `T1` or `T2`, whatever its root operator. But that's inappropriate for a function type `T1 => T2`; the code in `toTextFunction` attempted to use `atPrec(InfixPrec)` to correct for that, but that didn't work, because `argText` called `atPrec(GlobalPrec)` right away, hence we ended up running `atPrec(InfixPrec) { atPrec(GlobalPrec) { ... }}`, which means just `atPrec(GlobalPrec) { ... }`.
1 parent 6b85481 commit 3817733

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
135135
def toTextFunction(args: List[Type], isImplicit: Boolean, isErased: Boolean): Text =
136136
changePrec(GlobalPrec) {
137137
val argStr: Text =
138-
if (args.length == 2 && defn.isFunctionType(args.head)) {
139-
"(" ~ globalPrecArgText(args.head) ~ ")"
140-
} else if (args.length == 2 && !defn.isTupleType(args.head))
141-
atPrec(InfixPrec) { globalPrecArgText(args.head) }
138+
if (args.length == 2 && !defn.isTupleType(args.head))
139+
atPrec(InfixPrec) { argText(args.head) }
142140
else
143141
toTextTuple(args.init)
144142
(keywordText("erased ") provided isErased) ~ (keywordText("implicit ") provided isImplicit) ~ argStr ~ " => " ~ globalPrecArgText(args.last)

0 commit comments

Comments
 (0)