aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/ast/Desugar.scala16
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala6
-rw-r--r--tests/pos/i873.scala4
3 files changed, 20 insertions, 6 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:
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 52ea32bbc..4c07e07de 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -629,7 +629,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
def typedMatch(tree: untpd.Match, pt: Type)(implicit ctx: Context) = track("typedMatch") {
tree.selector match {
case EmptyTree =>
- typed(desugar.makeCaseLambda(tree.cases) withPos tree.pos, pt)
+ val arity = pt match {
+ case defn.FunctionType(args, _) => args.length
+ case _ => 1
+ }
+ typed(desugar.makeCaseLambda(tree.cases, arity) withPos tree.pos, pt)
case _ =>
val sel1 = typedExpr(tree.selector)
val selType = widenForMatchSelector(
diff --git a/tests/pos/i873.scala b/tests/pos/i873.scala
new file mode 100644
index 000000000..71c8a3959
--- /dev/null
+++ b/tests/pos/i873.scala
@@ -0,0 +1,4 @@
+object Test {
+ def call(k: (Int, Int) => Unit): Unit = ???
+ def test = call({ case (x, y) => ()})
+}