From f0e54c59520566b8d9d2b4dae8a4802de6b3a843 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 30 Oct 2015 09:53:58 +0100 Subject: Allow pattern matching anonymous functions of arity > 1 This is sepcified in Sec. 8.5 of the SLS. Fixes #873. Review by @smarter. --- src/dotty/tools/dotc/ast/Desugar.scala | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/dotty/tools/dotc/ast/Desugar.scala') diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index d1f101283..fe6e48aa8 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -556,14 +556,20 @@ object desugar { DefDef(nme.ANON_FUN, Nil, params :: Nil, tpt, body).withMods(synthetic), Closure(Nil, Ident(nme.ANON_FUN), EmptyTree)) - /** Expand partial function + /** If `nparams` == 1, expand partial function + * * { cases } * ==> - * x$0 => x$0 match { cases } + * x$1 => x$1 match { cases } + * + * If `nparams` != 1, expand instead to + * + * (x$0, ..., x${n-1}) => (x$0, ..., x${n-1}) match { cases } */ - def makeCaseLambda(cases: List[CaseDef])(implicit ctx: Context) = { - val param = makeSyntheticParameter() - Function(param :: Nil, Match(Ident(param.name), cases)) + def makeCaseLambda(cases: List[CaseDef], nparams: Int = 1)(implicit ctx: Context) = { + val params = (1 to nparams).toList.map(makeSyntheticParameter(_)) + val selector = makeTuple(params.map(p => Ident(p.name))) + Function(params, Match(selector, cases)) } /** Add annotation with class `cls` to tree: -- cgit v1.2.3