aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/Desugar.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-10-31 12:58:01 +0100
committerMartin Odersky <odersky@gmail.com>2016-02-16 15:23:43 +0100
commit29104c9755a9d6393959a416650422b84f0957f2 (patch)
tree19f844e71f9904c19714f4cab8c93fffc97db437 /src/dotty/tools/dotc/ast/Desugar.scala
parent5e8023335e641c9c05c6517a82764571e7ef6386 (diff)
downloaddotty-29104c9755a9d6393959a416650422b84f0957f2.tar.gz
dotty-29104c9755a9d6393959a416650422b84f0957f2.tar.bz2
dotty-29104c9755a9d6393959a416650422b84f0957f2.zip
Auto-uncurry n-ary functions.
Implements SIP #897.
Diffstat (limited to 'src/dotty/tools/dotc/ast/Desugar.scala')
-rw-r--r--src/dotty/tools/dotc/ast/Desugar.scala19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala
index 87694843a..c1083d26d 100644
--- a/src/dotty/tools/dotc/ast/Desugar.scala
+++ b/src/dotty/tools/dotc/ast/Desugar.scala
@@ -588,6 +588,25 @@ object desugar {
Function(params, Match(selector, cases))
}
+ /** Map n-ary function `(p1, ..., pn) => body` where n != 1 to unary function as follows:
+ *
+ * x$1 => {
+ * val p1 = x$1._1
+ * ...
+ * val pn = x$1._n
+ * body
+ * }
+ */
+ def makeUnaryCaseLambda(params: List[ValDef], body: Tree)(implicit ctx: Context): Tree = {
+ val param = makeSyntheticParameter()
+ def selector(n: Int) = Select(refOfDef(param), nme.selectorName(n))
+ val vdefs =
+ params.zipWithIndex.map{
+ case(param, idx) => cpy.ValDef(param)(rhs = selector(idx))
+ }
+ Function(param :: Nil, Block(vdefs, body))
+ }
+
/** Add annotation with class `cls` to tree:
* tree @cls
*/