diff options
author | Martin Odersky <odersky@gmail.com> | 2015-10-30 09:53:58 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-10-30 09:53:58 +0100 |
commit | f0e54c59520566b8d9d2b4dae8a4802de6b3a843 (patch) | |
tree | 92249fbd25a6cd76de690490bb114ac61b6c0fd1 /src/dotty/tools/dotc/ast/Desugar.scala | |
parent | 201ce2f1d11bf3940291f6c800ec9dedead6c2a5 (diff) | |
download | dotty-f0e54c59520566b8d9d2b4dae8a4802de6b3a843.tar.gz dotty-f0e54c59520566b8d9d2b4dae8a4802de6b3a843.tar.bz2 dotty-f0e54c59520566b8d9d2b4dae8a4802de6b3a843.zip |
Allow pattern matching anonymous functions of arity > 1
This is sepcified in Sec. 8.5 of the SLS. Fixes #873. Review by @smarter.
Diffstat (limited to 'src/dotty/tools/dotc/ast/Desugar.scala')
-rw-r--r-- | src/dotty/tools/dotc/ast/Desugar.scala | 16 |
1 files changed, 11 insertions, 5 deletions
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: |