@@ -204,36 +204,43 @@ trait TypesSupport:
204
204
prefix ++ plain(" { " ).l ++ refinedElems.flatMap(e => parseRefinedElem(e.name, e.info)) ++ plain(" }" ).l
205
205
}
206
206
}
207
+
208
+ case AppliedType (tpe, args) if defn.isTupleClass(tpe.typeSymbol) && args.length > 1 =>
209
+ inParens(commas(args.map(inner(_))))
210
+
211
+ case AppliedType (namedTuple, List (AppliedType (tuple1, names), AppliedType (tuple2, types)))
212
+ if namedTuple.typeSymbol == Symbol .requiredModule(" scala.NamedTuple" ).typeMember(" NamedTuple" )
213
+ && defn.isTupleClass(tuple1.typeSymbol) && defn.isTupleClass(tuple2.typeSymbol) && names.length == types.length
214
+ && names.forall { case ConstantType (StringConstant (_)) => true case _ => false } =>
215
+ val elems = names
216
+ .collect { case ConstantType (StringConstant (s)) => s }
217
+ .zip(types)
218
+ .map((name, tpe) => plain(name) +: plain(" : " ) +: inner(tpe))
219
+ inParens(commas(elems))
220
+
221
+ case t @ AppliedType (tpe, List (lhs, rhs)) if isInfix(t) =>
222
+ inParens(inner(lhs), shouldWrapInParens(lhs, t, true ))
223
+ ++ plain(" " ).l
224
+ ++ inner(tpe)
225
+ ++ plain(" " ).l
226
+ ++ inParens(inner(rhs), shouldWrapInParens(rhs, t, false ))
227
+
228
+ case t @ AppliedType (tpe, args) if t.isFunctionType =>
229
+ val arrow = if t.isContextFunctionType then " ?=> " else " => "
230
+ args match
231
+ case Nil => Nil
232
+ case List (rtpe) => plain(" ()" ).l ++ keyword(arrow).l ++ inner(rtpe)
233
+ case List (arg, rtpe) =>
234
+ val wrapInParens = stripAnnotated(arg) match
235
+ case _ : TermRef | _ : TypeRef | _ : ConstantType | _ : ParamRef => false
236
+ case at : AppliedType if ! isInfix(at) && ! at.isFunctionType && ! at.isTupleN => false
237
+ case _ => true
238
+ inParens(inner(arg), wrapInParens) ++ keyword(arrow).l ++ inner(rtpe)
239
+ case _ =>
240
+ plain(" (" ).l ++ commas(args.init.map(inner(_))) ++ plain(" )" ).l ++ keyword(arrow).l ++ inner(args.last)
241
+
207
242
case t @ AppliedType (tpe, typeList) =>
208
- import dotty .tools .dotc .util .Chars ._
209
- if defn.isTupleClass(tpe.typeSymbol) && typeList.length != 1 then
210
- typeList match
211
- case Nil => Nil
212
- case args => inParens(commas(args.map(inner(_))))
213
- else if isInfix(t) then
214
- val lhs = typeList.head
215
- val rhs = typeList.last
216
- inParens(inner(lhs), shouldWrapInParens(lhs, t, true ))
217
- ++ plain(" " ).l
218
- ++ inner(tpe)
219
- ++ plain(" " ).l
220
- ++ inParens(inner(rhs), shouldWrapInParens(rhs, t, false ))
221
- else if t.isFunctionType then
222
- val arrow = if t.isContextFunctionType then " ?=> " else " => "
223
- typeList match
224
- case Nil =>
225
- Nil
226
- case Seq (rtpe) =>
227
- plain(" ()" ).l ++ keyword(arrow).l ++ inner(rtpe)
228
- case Seq (arg, rtpe) =>
229
- val partOfSignature = stripAnnotated(arg) match
230
- case _ : TermRef | _ : TypeRef | _ : ConstantType | _ : ParamRef => inner(arg)
231
- case at : AppliedType if ! isInfix(at) && ! at.isFunctionType && ! at.isTupleN => inner(arg)
232
- case _ => inParens(inner(arg))
233
- partOfSignature ++ keyword(arrow).l ++ inner(rtpe)
234
- case args =>
235
- plain(" (" ).l ++ commas(args.init.map(inner(_))) ++ plain(" )" ).l ++ keyword(arrow).l ++ inner(args.last)
236
- else inner(tpe) ++ plain(" [" ).l ++ commas(typeList.map { t => t match
243
+ inner(tpe) ++ plain(" [" ).l ++ commas(typeList.map { t => t match
237
244
case _ : TypeBounds => keyword(" _" ).l ++ inner(t)
238
245
case _ => topLevelProcess(t)
239
246
}) ++ plain(" ]" ).l
0 commit comments