@@ -1316,33 +1316,39 @@ object desugar {
1316
1316
Function (params, Match (makeSelector(selector, checkMode), cases))
1317
1317
}
1318
1318
1319
- /** Map n-ary function `(p1 , ..., pn ) => body` where n != 1 to unary function as follows:
1319
+ /** Map n-ary function `(x1: T1 , ..., xn: Tn ) => body` where n != 1 to unary function as follows:
1320
1320
*
1321
- * x$1 => {
1322
- * def p1 = x$1._1
1321
+ * ( x$1: (T1, ..., Tn)) => {
1322
+ * def x1: T1 = x$1._1
1323
1323
* ...
1324
- * def pn = x$1._n
1324
+ * def xn: Tn = x$1._n
1325
1325
* body
1326
1326
* }
1327
1327
*
1328
1328
* or if `isGenericTuple`
1329
1329
*
1330
- * x$1 => {
1331
- * def p1 = x$1.apply(0)
1330
+ * ( x$1: (T1, ... Tn) => {
1331
+ * def x1: T1 = x$1.apply(0)
1332
1332
* ...
1333
- * def pn = x$1.apply(n-1)
1333
+ * def xn: Tn = x$1.apply(n-1)
1334
1334
* body
1335
1335
* }
1336
+ *
1337
+ * If some of the Ti's are absent, omit the : (T1, ..., Tn) type ascription
1338
+ * in the selector.
1336
1339
*/
1337
1340
def makeTupledFunction (params : List [ValDef ], body : Tree , isGenericTuple : Boolean )(implicit ctx : Context ): Tree = {
1338
- val param = makeSyntheticParameter()
1341
+ val param = makeSyntheticParameter(
1342
+ tpt =
1343
+ if params.exists(_.tpt.isEmpty) then TypeTree ()
1344
+ else Tuple (params.map(_.tpt)))
1339
1345
def selector (n : Int ) =
1340
1346
if (isGenericTuple) Apply (Select (refOfDef(param), nme.apply), Literal (Constant (n)))
1341
1347
else Select (refOfDef(param), nme.selectorName(n))
1342
1348
val vdefs =
1343
1349
params.zipWithIndex.map {
1344
1350
case (param, idx) =>
1345
- DefDef (param.name, Nil , Nil , TypeTree () , selector(idx)).withSpan(param.span)
1351
+ DefDef (param.name, Nil , Nil , param.tpt , selector(idx)).withSpan(param.span)
1346
1352
}
1347
1353
Function (param :: Nil , Block (vdefs, body))
1348
1354
}
0 commit comments