Skip to content

Commit 390071e

Browse files
committed
Refactored polyfunction desugaring
1 parent 3c6c5a7 commit 390071e

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,20 +1418,8 @@ object desugar {
14181418
}
14191419
}
14201420

1421-
// begin desugar
1422-
1423-
// Special case for `Parens` desugaring: unlike all the desugarings below,
1424-
// its output is not a new tree but an existing one whose position should
1425-
// be preserved, so we shouldn't call `withPos` on it.
1426-
tree match {
1427-
case Parens(t) =>
1428-
return t
1429-
case _ =>
1430-
}
1431-
1432-
val desugared = tree match {
1433-
case PolyFunction(targs, body) =>
1434-
val Function(vargs, res) = body
1421+
def makePolyFunction(targs: List[Tree], body: Tree): Tree = body match {
1422+
case Function(vargs, res) =>
14351423
// TODO: Figure out if we need a `PolyFunctionWithMods` instead.
14361424
val mods = body match {
14371425
case body: FunctionWithMods => body.mods
@@ -1455,10 +1443,28 @@ object desugar {
14551443

14561444
val applyVParams = vargs.asInstanceOf[List[ValDef]]
14571445
.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-
))
1446+
New(Template(emptyConstructor, List(polyFunctionTpt), Nil, EmptyValDef,
1447+
List(DefDef(nme.apply, applyTParams, List(applyVParams), TypeTree(), res))
1448+
))
14611449
}
1450+
case _ =>
1451+
EmptyTree //may happen for erroneous input
1452+
}
1453+
1454+
// begin desugar
1455+
1456+
// Special case for `Parens` desugaring: unlike all the desugarings below,
1457+
// its output is not a new tree but an existing one whose position should
1458+
// be preserved, so we shouldn't call `withPos` on it.
1459+
tree match {
1460+
case Parens(t) =>
1461+
return t
1462+
case _ =>
1463+
}
1464+
1465+
val desugared = tree match {
1466+
case PolyFunction(targs, body) =>
1467+
makePolyFunction(targs, body) orElse tree
14621468
case SymbolLit(str) =>
14631469
Literal(Constant(scala.Symbol(str)))
14641470
case InterpolatedString(id, segments) =>

0 commit comments

Comments
 (0)