From 2d33c00ec0fd0b4a4b863ac02630cb87bc71c53d Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Mon, 14 May 2012 11:25:26 +0200 Subject: fix SI-5384 make TreeInfo recognize constructor calls after named arguments transformation. --- src/compiler/scala/reflect/internal/TreeInfo.scala | 24 ++++++++++++++++++++-- test/files/pos/t5384.scala | 7 +++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test/files/pos/t5384.scala diff --git a/src/compiler/scala/reflect/internal/TreeInfo.scala b/src/compiler/scala/reflect/internal/TreeInfo.scala index 2251310f35..1528061adb 100644 --- a/src/compiler/scala/reflect/internal/TreeInfo.scala +++ b/src/compiler/scala/reflect/internal/TreeInfo.scala @@ -221,9 +221,29 @@ abstract class TreeInfo { case _ => false } + /** + * Named arguments can transform a constructor call into a block, e.g. + * (b = foo, a = bar) + * is transformed to + * { val x$1 = foo + * val x$2 = bar + * (x$2, x$1) + * } + */ + def stripNamedApplyBlock(tree: Tree) = tree match { + case Block(stats, expr) if stats.forall(_.isInstanceOf[ValDef]) => + expr + case _ => + tree + } + /** Is tree a self or super constructor call? */ - def isSelfOrSuperConstrCall(tree: Tree) = - isSelfConstrCall(tree) || isSuperConstrCall(tree) + def isSelfOrSuperConstrCall(tree: Tree) = { + // stripNamedApply for SI-3584: adaptToImplicitMethod in Typers creates a special context + // for implicit search in constructor calls, adaptToImplicitMethod(isSelfOrConstrCall) + val tree1 = stripNamedApplyBlock(tree) + isSelfConstrCall(tree1) || isSuperConstrCall(tree1) + } /** Is tree a variable pattern? */ def isVarPattern(pat: Tree): Boolean = pat match { diff --git a/test/files/pos/t5384.scala b/test/files/pos/t5384.scala new file mode 100644 index 0000000000..4e297d5935 --- /dev/null +++ b/test/files/pos/t5384.scala @@ -0,0 +1,7 @@ +class A(x: String, y: Int)(implicit o: String) +class B1(implicit o: String) extends A(y = 5, x = "a") +class B2(implicit o: String) extends A("a", 5) +class B3(implicit o: String) extends A(y = 5, x = "a")(o) + +class AM[E: Manifest](val x: Unit = (), y: Unit) +class BM[E: Manifest] extends AM[E](y = ()) -- cgit v1.2.3