summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/transform/Constructors.scala7
-rw-r--r--test/files/run/bug4680.check60
-rw-r--r--test/files/run/bug4680.scala71
3 files changed, 138 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala
index c1efe4843d..6ea6f9c4d6 100644
--- a/src/compiler/scala/tools/nsc/transform/Constructors.scala
+++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala
@@ -556,6 +556,13 @@ abstract class Constructors extends Transform with ast.TreeDSL {
var (uptoSuperStats, remainingConstrStats) = splitAtSuper(constrStatBuf.toList)
+ /** XXX This is not corect: remainingConstrStats.nonEmpty excludes too much,
+ * but excluding it includes too much. The constructor sequence being mimicked
+ * needs to be reproduced with total fidelity.
+ *
+ * See test case files/run/bug4680.scala, the output of which is wrong in many
+ * particulars.
+ */
val needsDelayedInit =
(clazz isSubClass DelayedInitClass) /*&& !(defBuf exists isInitDef)*/ && remainingConstrStats.nonEmpty
diff --git a/test/files/run/bug4680.check b/test/files/run/bug4680.check
new file mode 100644
index 0000000000..b5cfc651f2
--- /dev/null
+++ b/test/files/run/bug4680.check
@@ -0,0 +1,60 @@
+
+
+// new C { }
+-A -B -C
+
+// new C { 5 }
+-A -B -C
+A+ B+ C+
+
+// new D()
+-A -B -C -D
+A+ B+ C+ D+
+
+// new D() { }
+-A -B -C -D
+A+ B+ C+ D+
+
+// new D() { val x = 5 }
+-A -B -C -D
+A+ B+ C+ D+
+A+ B+ C+ D+
+
+// new { val x = 5 } with D()
+-A -B -C -D
+A+ B+ C+ D+
+
+// new E() { val x = 5 }
+-A -B -C -D
+A+ B+ C+ D+ E+
+-E
+
+A+ B+ C+ D+ E+
+
+A+ B+ C+ D+ E+
+
+
+// new { val x = 5 } with E()
+-A -B -C -D
+A+ B+ C+ D+ E+
+-E
+
+A+ B+ C+ D+ E+
+
+
+// new { val x = 5 } with E() { }
+-A -B -C -D
+A+ B+ C+ D+ E+
+-E
+
+A+ B+ C+ D+ E+
+
+
+// new { val x = 5 } with E() { 5 }
+-A -B -C -D
+A+ B+ C+ D+ E+
+-E
+
+A+ B+ C+ D+ E+
+
+A+ B+ C+ D+ E+
diff --git a/test/files/run/bug4680.scala b/test/files/run/bug4680.scala
new file mode 100644
index 0000000000..d5c8d0e7af
--- /dev/null
+++ b/test/files/run/bug4680.scala
@@ -0,0 +1,71 @@
+trait A extends DelayedInit {
+ print("-A ")
+
+ def delayedInit(body: => Unit) = {
+ body
+ postConstructionCode
+ }
+ protected def postConstructionCode: Unit = {
+ print("\nA+ ")
+ }
+}
+trait B extends A {
+ print("-B ")
+ override protected def postConstructionCode: Unit = {
+ super.postConstructionCode
+ print("B+ ")
+ }
+}
+
+trait C extends B {
+ print("-C ")
+ override protected def postConstructionCode: Unit = {
+ super.postConstructionCode
+ print("C+ ")
+ }
+}
+
+class D() extends C {
+ print("-D ")
+ override protected def postConstructionCode: Unit = {
+ super.postConstructionCode
+ print("D+ ")
+ }
+}
+class E() extends D() {
+ println("-E")
+ override protected def postConstructionCode: Unit = {
+ super.postConstructionCode
+ println("E+")
+ }
+}
+
+
+object Test {
+ def p(msg: String) = println("\n\n// " + msg)
+
+ def main(args: Array[String]) {
+ p("new C { }")
+ new C { }
+ p("new C { 5 }")
+ new C { 5 }
+
+ p("new D()")
+ new D()
+ p("new D() { }")
+ new D() { }
+ p("new D() { val x = 5 }")
+ new D() { val x = 5 }
+ p("new { val x = 5 } with D()")
+ new { val x = 5 } with D()
+
+ p("new E() { val x = 5 }")
+ new E() { val x = 5 }
+ p("new { val x = 5 } with E()")
+ new { val x = 5 } with E()
+ p("new { val x = 5 } with E() { }")
+ new { val x = 5 } with E() { }
+ p("new { val x = 5 } with E() { 5 }")
+ new { val x = 5 } with E() { 5 }
+ }
+}