aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/PostTyper.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-01-29 21:48:55 +0100
committerMartin Odersky <odersky@gmail.com>2016-02-19 14:02:17 +0100
commit8441de7a907996361a78d744d3364cee3d558f84 (patch)
treea553bc1c18466324d0f2898af5c9c4d48a4c5fe4 /src/dotty/tools/dotc/transform/PostTyper.scala
parent1d585f1172d563051c0710008568b3b53728281f (diff)
downloaddotty-8441de7a907996361a78d744d3364cee3d558f84.tar.gz
dotty-8441de7a907996361a78d744d3364cee3d558f84.tar.bz2
dotty-8441de7a907996361a78d744d3364cee3d558f84.zip
Allow Named Arguments in TypeArgs
Lets one also pass named arguments to methods.
Diffstat (limited to 'src/dotty/tools/dotc/transform/PostTyper.scala')
-rw-r--r--src/dotty/tools/dotc/transform/PostTyper.scala42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/transform/PostTyper.scala b/src/dotty/tools/dotc/transform/PostTyper.scala
index b38858b72..d552c16f7 100644
--- a/src/dotty/tools/dotc/transform/PostTyper.scala
+++ b/src/dotty/tools/dotc/transform/PostTyper.scala
@@ -143,6 +143,41 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
}
}
+ private def normalizeTypeArgs(tree: TypeApply)(implicit ctx: Context): TypeApply = tree.tpe match {
+ case pt: PolyType => // wait for more arguments coming
+ tree
+ case _ =>
+ def decompose(tree: TypeApply): (Tree, List[Tree]) = tree.fun match {
+ case fun: TypeApply =>
+ val (tycon, args) = decompose(fun)
+ (tycon, args ++ tree.args)
+ case _ =>
+ (tree.fun, tree.args)
+ }
+ def reorderArgs(pnames: List[Name], namedArgs: List[NamedArg], otherArgs: List[Tree]): List[Tree] = pnames match {
+ case pname :: pnames1 =>
+ namedArgs.partition(_.name == pname) match {
+ case (NamedArg(_, arg) :: _, namedArgs1) =>
+ arg :: reorderArgs(pnames1, namedArgs1, otherArgs)
+ case _ =>
+ val otherArg :: otherArgs1 = otherArgs
+ otherArg :: reorderArgs(pnames1, namedArgs, otherArgs1)
+ }
+ case nil =>
+ assert(namedArgs.isEmpty && otherArgs.isEmpty)
+ Nil
+ }
+ val (tycon, args) = decompose(tree)
+ tycon.tpe.widen match {
+ case PolyType(pnames) =>
+ val (namedArgs, otherArgs) = args.partition(isNamedArg)
+ val args1 = reorderArgs(pnames, namedArgs.asInstanceOf[List[NamedArg]], otherArgs)
+ TypeApply(tycon, args1).withPos(tree.pos).withType(tree.tpe)
+ case _ =>
+ tree
+ }
+ }
+
override def transform(tree: Tree)(implicit ctx: Context): Tree =
try normalizeTree(tree) match {
case tree: Ident =>
@@ -152,15 +187,16 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
}
case tree: Select =>
transformSelect(paramFwd.adaptRef(tree), Nil)
- case tree @ TypeApply(fn, args) =>
+ case tree: TypeApply =>
+ val tree1 @ TypeApply(fn, args) = normalizeTypeArgs(tree)
Checking.checkBounds(args, fn.tpe.widen.asInstanceOf[PolyType])
fn match {
case sel: Select =>
val args1 = transform(args)
val sel1 = transformSelect(sel, args1)
- if (superAcc.isProtectedAccessor(sel1)) sel1 else cpy.TypeApply(tree)(sel1, args1)
+ if (superAcc.isProtectedAccessor(sel1)) sel1 else cpy.TypeApply(tree1)(sel1, args1)
case _ =>
- super.transform(tree)
+ super.transform(tree1)
}
case tree @ Assign(sel: Select, _) =>
superAcc.transformAssign(super.transform(tree))