aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/PostTyper.scala
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2016-02-19 17:24:23 +0100
committerodersky <odersky@gmail.com>2016-02-19 17:24:23 +0100
commit2217a4ec9ea563f01b07c852a3834d738cd6439d (patch)
tree4ac8601a9fc598d2faeaf940fb35fa12eb6b4c1f /src/dotty/tools/dotc/transform/PostTyper.scala
parentea407f143591aa9ffd0fd0f9a25a9ec9e812e76c (diff)
parent12301586418ebad71c7d7d5ce9a53ea4909f675a (diff)
downloaddotty-2217a4ec9ea563f01b07c852a3834d738cd6439d.tar.gz
dotty-2217a4ec9ea563f01b07c852a3834d738cd6439d.tar.bz2
dotty-2217a4ec9ea563f01b07c852a3834d738cd6439d.zip
Merge pull request #1072 from dotty-staging/change-isVolatile-2
Change is volatile 2
Diffstat (limited to 'src/dotty/tools/dotc/transform/PostTyper.scala')
-rw-r--r--src/dotty/tools/dotc/transform/PostTyper.scala47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/transform/PostTyper.scala b/src/dotty/tools/dotc/transform/PostTyper.scala
index 14edaa7b5..d552c16f7 100644
--- a/src/dotty/tools/dotc/transform/PostTyper.scala
+++ b/src/dotty/tools/dotc/transform/PostTyper.scala
@@ -68,7 +68,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
// TODO fill in
}
- /** Check bounds of AppliedTypeTrees.
+ /** Check bounds of AppliedTypeTrees and TypeApplys.
* Replace type trees with TypeTree nodes.
* Replace constant expressions with Literal nodes.
* Note: Demanding idempotency instead of purity in literalize is strictly speaking too loose.
@@ -99,6 +99,9 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
*/
private def normalizeTree(tree: Tree)(implicit ctx: Context): Tree = tree match {
case tree: TypeTree => tree
+ case TypeApply(fn, args) =>
+ Checking.checkBounds(args, fn.tpe.widen.asInstanceOf[PolyType])
+ tree
case _ =>
if (tree.isType) {
Checking.typeChecker.traverse(tree)
@@ -140,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 =>
@@ -149,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))