@@ -1430,22 +1430,35 @@ object desugar {
1430
1430
}
1431
1431
1432
1432
val desugared = tree match {
1433
- case PolyFunction (targs, body) if (ctx.mode.is(Mode .Type )) =>
1434
- // Desugar [T_1, ..., T_M] -> (P_1, ..., P_N) => R
1435
- // Into scala.PolyFunction { def apply[T_1, ..., T_M](x$1: P_1, ..., x$N: P_N): R }
1436
- val Function (vargs, resType) = body
1433
+ case PolyFunction (targs, body) =>
1434
+ val Function (vargs, res) = body
1437
1435
// TODO: Figure out if we need a `PolyFunctionWithMods` instead.
1438
1436
val mods = body match {
1439
1437
case body : FunctionWithMods => body.mods
1440
1438
case _ => untpd.EmptyModifiers
1441
1439
}
1440
+ val polyFunctionTpt = ref(defn.PolyFunctionType )
1442
1441
val applyTParams = targs.asInstanceOf [List [TypeDef ]]
1443
- val applyVParams = vargs.zipWithIndex.map { case (p, n) =>
1444
- makeSyntheticParameter(n + 1 , p).withAddedFlags(mods.flags)
1442
+ if (ctx.mode.is(Mode .Type )) {
1443
+ // Desugar [T_1, ..., T_M] -> (P_1, ..., P_N) => R
1444
+ // Into scala.PolyFunction { def apply[T_1, ..., T_M](x$1: P_1, ..., x$N: P_N): R }
1445
+
1446
+ val applyVParams = vargs.zipWithIndex.map { case (p, n) =>
1447
+ makeSyntheticParameter(n + 1 , p).withAddedFlags(mods.flags)
1448
+ }
1449
+ RefinedTypeTree (polyFunctionTpt, List (
1450
+ DefDef (nme.apply, applyTParams, List (applyVParams), res, EmptyTree )
1451
+ ))
1452
+ } else {
1453
+ // Desugar [T_1, ..., T_M] -> (x_1: P_1, ..., x_N: P_N) => body
1454
+ // Into new scala.PolyFunction { def apply[T_1, ..., T_M](x_1: P_1, ..., x_N: P_N) = body }
1455
+
1456
+ val applyVParams = vargs.asInstanceOf [List [ValDef ]]
1457
+ .map(varg => varg.withAddedFlags(mods.flags | Param ))
1458
+ New (Template (emptyConstructor, List (polyFunctionTpt), Nil , EmptyValDef ,
1459
+ List (DefDef (nme.apply, applyTParams, List (applyVParams), TypeTree (), res))
1460
+ ))
1445
1461
}
1446
- RefinedTypeTree (ref(defn.PolyFunctionType ), List (
1447
- DefDef (nme.apply, applyTParams, List (applyVParams), resType, EmptyTree )
1448
- ))
1449
1462
case SymbolLit (str) =>
1450
1463
Literal (Constant (scala.Symbol (str)))
1451
1464
case InterpolatedString (id, segments) =>
0 commit comments