From 574a148fd561a793ee522c2be18ee02214236d80 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 16 Mar 2014 12:39:56 +0100 Subject: Added auto-tupling. Auto-tupling should satisfy the following spec. 1. An application `f(args)` where `f` is a non-overloaded method which has a single, non-repeated parameter as its first parameter list and where args consists of two or more arguments is expanded to `f((args))`. 2. A constructor pattern `C(args)` where `C.unapply` is a non-overloaded method which has a single, non-repeated parameter as its first parameter list and where args consists of two or more arguments is expanded to `C((args))`. Auto-tupling can be disabled by language feature "noAutoTupling". Conflicts: test/dotc/tests.scala --- src/dotty/tools/dotc/typer/Typer.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/dotty/tools/dotc/typer/Typer.scala') diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 17c77be89..f961a4544 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1072,8 +1072,16 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } } - def adaptToArgs(wtp: Type, pt: FunProto) = wtp match { - case _: MethodType | _: PolyType => tree + def adaptToArgs(wtp: Type, pt: FunProto): Tree = wtp match { + case _: MethodType | _: PolyType => + def isUnary = wtp.firstParamTypes match { + case ptype :: Nil => !ptype.isRepeatedParam + case _ => false + } + if (pt.args.lengthCompare(1) > 0 && isUnary && ctx.canAutoTuple) + adaptToArgs(wtp, pt.tupled) + else + tree case _ => tryInsertApply(tree, pt) { val more = tree match { case Apply(_, _) => " more" -- cgit v1.2.3