diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/t9697.check | 2 | ||||
-rw-r--r-- | test/files/run/t9697.scala | 77 |
2 files changed, 78 insertions, 1 deletions
diff --git a/test/files/run/t9697.check b/test/files/run/t9697.check index bbd9fd19cf..2a4f01c14f 100644 --- a/test/files/run/t9697.check +++ b/test/files/run/t9697.check @@ -1 +1 @@ -warning: there were 6 deprecation warnings (since 2.11.0); re-run with -deprecation for details +warning: there were 9 deprecation warnings (since 2.11.0); re-run with -deprecation for details diff --git a/test/files/run/t9697.scala b/test/files/run/t9697.scala index b837feb237..eb8e44f8fc 100644 --- a/test/files/run/t9697.scala +++ b/test/files/run/t9697.scala @@ -101,6 +101,57 @@ package t4683d { } } +package t4683e { + class DelayedInitTest { + def a = log("uh") + class B extends DelayedInit { + a + def delayedInit(body: => Unit): Unit = body + } + } +} + +package t4683f { + class Foo extends DelayedInit { + log("fooInit") + def delayedInit(newBody: => Unit): Unit = { + log("delayedInit") + inits = { + val f = () => newBody + if (inits == null) { + log("initsNull") + List(f) + } else + f :: inits + } + } + def foo = log("foo") + var inits: List[() => Unit] = Nil + } + + class Bar extends Foo { + log("barInit") + def bar = foo + def newBaz: Foo = new Baz + private class Baz extends Foo { + log("bazInit") + bar + } + } +} + +package t4683g { + trait MatExpWorld { self => + class T extends Runner { val expWorld: self.type = self } + } + + trait Runner extends DelayedInit { + def delayedInit(init: => Unit): Unit = init + val expWorld: MatExpWorld + } +} + + object Test extends App { new t9697.C() log.check("1234") @@ -124,4 +175,30 @@ object Test extends App { new t4683d.Injector().test log.check("k") + + val dit = new t4683e.DelayedInitTest() + new dit.B() + log.check("uh") + + val fuu = new t4683f.Foo + log.check("delayedInitinitsNull") + fuu.inits.foreach(_.apply()) + log.check("fooInit") + assert(fuu.inits == Nil) // the (delayed) initializer of Foo sets the inits field to Nil + + val brr = new t4683f.Bar + log.check("delayedInitinitsNulldelayedInit") // delayedInit is called once for each constructor + brr.inits.foreach(_.apply()) + log.check("barInitfooInit") + assert(brr.inits == Nil) + + val bzz = brr.newBaz + log.check("delayedInitinitsNulldelayedInit") + bzz.inits.foreach(_.apply()) + log.check("bazInitfoofooInit") + assert(bzz.inits == Nil) + + val mew = new t4683g.MatExpWorld { } + val mt = new mew.T + assert(mt.expWorld == mew) } |