diff options
author | Martin Odersky <odersky@gmail.com> | 2014-03-16 12:39:56 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-03-20 13:02:29 +0100 |
commit | 574a148fd561a793ee522c2be18ee02214236d80 (patch) | |
tree | 34d99eaeed0a35d549c04d8db3ec409e9293baed /src/dotty/tools/dotc/typer/ProtoTypes.scala | |
parent | bff6b093d28bfc6918fa86d640353ba60b1a24e4 (diff) | |
download | dotty-574a148fd561a793ee522c2be18ee02214236d80.tar.gz dotty-574a148fd561a793ee522c2be18ee02214236d80.tar.bz2 dotty-574a148fd561a793ee522c2be18ee02214236d80.zip |
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
Diffstat (limited to 'src/dotty/tools/dotc/typer/ProtoTypes.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/ProtoTypes.scala | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index b4068408b..74be3f4cd 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -187,6 +187,20 @@ object ProtoTypes { typer.adapt(targ, formal) } + private var myTupled: Type = NoType + + /** The same proto-type but with all arguments combined in a single tuple */ + def tupled: FunProto = myTupled match { + case pt: FunProto => + pt + case _ => + myTupled = new FunProto(untpd.Tuple(args) :: Nil, resultType, typer) + tupled + } + + /** Somebody called the `tupled` method of this prototype */ + def isTupled: Boolean = myTupled.isInstanceOf[FunProto] + override def toString = s"FunProto(${args mkString ","} => $resultType)" def map(tm: TypeMap)(implicit ctx: Context): FunProto = |