summaryrefslogtreecommitdiff
path: root/test/files/run/delay-bad.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-03-21 14:12:25 -0700
committerPaul Phillips <paulp@improving.org>2012-03-21 14:14:51 -0700
commitc535aec63f6e30b0b689ad60b1dd2f1b78c66039 (patch)
treeaf7401c6920319a5ebbc495d0b4c61e9363367ec /test/files/run/delay-bad.scala
parenta36a05933499acd3aeeb414d36099ea8ae6e6ca9 (diff)
downloadscala-c535aec63f6e30b0b689ad60b1dd2f1b78c66039.tar.gz
scala-c535aec63f6e30b0b689ad60b1dd2f1b78c66039.tar.bz2
scala-c535aec63f6e30b0b689ad60b1dd2f1b78c66039.zip
An illustrative delayedInit test.
Diffstat (limited to 'test/files/run/delay-bad.scala')
-rw-r--r--test/files/run/delay-bad.scala77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/files/run/delay-bad.scala b/test/files/run/delay-bad.scala
new file mode 100644
index 0000000000..43acc1ea3d
--- /dev/null
+++ b/test/files/run/delay-bad.scala
@@ -0,0 +1,77 @@
+trait A extends DelayedInit
+{
+ print("-A")
+
+ def delayedInit(body: => Unit) = {
+ body
+ postConstructionCode
+ }
+ def postConstructionCode: Unit = {
+ print("\n A+")
+ }
+}
+trait B extends A {
+ print(" -B")
+ override def postConstructionCode: Unit = {
+ super.postConstructionCode
+ print(" B+")
+ }
+}
+
+trait C extends B {
+ print(" -C")
+ override def postConstructionCode: Unit = {
+ super.postConstructionCode
+ print(" C+")
+ }
+}
+
+class D() extends C {
+ print(" -D")
+ override def postConstructionCode: Unit = {
+ super.postConstructionCode
+ print(" D+")
+ }
+}
+class E() extends D() {
+ print(" -E")
+ override def postConstructionCode: Unit = {
+ super.postConstructionCode
+ print(" E+")
+ }
+}
+
+object Test {
+ def p(msg: String) = println("\n\n// " + msg)
+
+ def main(args: Array[String]) {
+ val f: A => Unit = _ => ()
+
+ p("new C { }")
+ f(new C { })
+ p("new C { 5 }")
+ f(new C { 5 })
+
+ p("new D()")
+ f(new D())
+ p("new D() { }")
+ f(new D() { })
+
+ p("new D() { val x = 5 }")
+ f(new D() { val x = 5 })
+ p("new { val x = 5 } with D()")
+ f(new { val x = 5 } with D())
+
+ p("new E() { val x = 5 }")
+ f(new E() { val x = 5 })
+ p("new { val x = 5 } with E()")
+ f(new { val x = 5 } with E())
+
+ p("new { val x = 5 } with E() { }")
+ f(new { val x = 5 } with E() { })
+ p("new { val x = 5 } with E() { 5 }")
+ f(new { val x = 5 } with E() { 5 })
+
+ println("")
+ }
+}