summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2012-05-14 11:25:26 +0200
committerLukas Rytz <lukas.rytz@epfl.ch>2012-05-14 11:31:14 +0200
commit2d33c00ec0fd0b4a4b863ac02630cb87bc71c53d (patch)
tree09be696bab8e3a2d31338bce6067b30ab44dc30c
parentf1d81c9b9b300b2f526c03a27600e6fe481fc7c6 (diff)
downloadscala-2d33c00ec0fd0b4a4b863ac02630cb87bc71c53d.tar.gz
scala-2d33c00ec0fd0b4a4b863ac02630cb87bc71c53d.tar.bz2
scala-2d33c00ec0fd0b4a4b863ac02630cb87bc71c53d.zip
fix SI-5384
make TreeInfo recognize constructor calls after named arguments transformation.
-rw-r--r--src/compiler/scala/reflect/internal/TreeInfo.scala24
-rw-r--r--test/files/pos/t5384.scala7
2 files changed, 29 insertions, 2 deletions
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.
+ * <init>(b = foo, a = bar)
+ * is transformed to
+ * { val x$1 = foo
+ * val x$2 = bar
+ * <init>(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 = ())