diff options
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/SD-235.scala | 39 | ||||
-rw-r--r-- | test/files/run/delambdafy_t6028.check | 16 | ||||
-rw-r--r-- | test/files/run/local_obj.scala | 9 | ||||
-rw-r--r-- | test/files/run/t6028.check | 16 | ||||
-rw-r--r-- | test/files/run/t9697.check | 1 | ||||
-rw-r--r-- | test/files/run/t9697.scala | 204 | ||||
-rw-r--r-- | test/files/run/t9920.scala | 17 | ||||
-rw-r--r-- | test/files/run/t9920b.scala | 17 | ||||
-rw-r--r-- | test/files/run/t9920c.scala | 21 | ||||
-rw-r--r-- | test/files/run/t9920d.scala | 14 |
10 files changed, 340 insertions, 14 deletions
diff --git a/test/files/run/SD-235.scala b/test/files/run/SD-235.scala new file mode 100644 index 0000000000..eb79c6fe71 --- /dev/null +++ b/test/files/run/SD-235.scala @@ -0,0 +1,39 @@ +class C { + var ORef: Object = null + def test = { + object O { + assert(!Thread.holdsLock(C.this)) + assert(Thread.holdsLock(ORef)) + } + val captor = new { def oh = O } + val refField = captor.getClass.getDeclaredFields.last + refField.setAccessible(true) + assert(refField.getType.toString.contains("LazyRef"), refField) + ORef = refField.get(captor) + O + } +} + +class D { + var ORef: Object = null + def test = { + lazy val O = { + assert(!Thread.holdsLock(D.this)) + assert(Thread.holdsLock(ORef)) + "O" + } + val captor = new { def oh = O } + val refField = captor.getClass.getDeclaredFields.last + refField.setAccessible(true) + assert(refField.getType.toString.contains("LazyRef"), refField) + ORef = refField.get(captor) + O + } +} + +object Test { + def main(args: Array[String]): Unit = { + new C().test + new D().test + } +} diff --git a/test/files/run/delambdafy_t6028.check b/test/files/run/delambdafy_t6028.check index eaba70ee1a..86cb1d5e97 100644 --- a/test/files/run/delambdafy_t6028.check +++ b/test/files/run/delambdafy_t6028.check @@ -15,7 +15,7 @@ package <empty> { } }; def bar(barParam: String): Object = { - @volatile var MethodLocalObject$module: runtime.VolatileObjectRef = scala.runtime.VolatileObjectRef.zero(); + lazy <artifact> val MethodLocalObject$module: scala.runtime.LazyRef = new scala.runtime.LazyRef(); T.this.MethodLocalObject$1(barParam, MethodLocalObject$module) }; def tryy(tryyParam: String): Function0 = { @@ -42,12 +42,14 @@ package <empty> { <synthetic> <stable> <artifact> def $outer(): T = MethodLocalObject$2.this.$outer; <synthetic> <stable> <artifact> def $outer(): T = MethodLocalObject$2.this.$outer }; - final <stable> private[this] def MethodLocalObject$1(barParam$1: String, MethodLocalObject$module$1: runtime.VolatileObjectRef): T#MethodLocalObject$2.type = { - if (MethodLocalObject$module$1.elem.$asInstanceOf[T#MethodLocalObject$2.type]().eq(null)) - T.this.synchronized[Unit](if (MethodLocalObject$module$1.elem.$asInstanceOf[T#MethodLocalObject$2.type]().eq(null)) - MethodLocalObject$module$1.elem = new T#MethodLocalObject$2.type(T.this, barParam$1)); - MethodLocalObject$module$1.elem.$asInstanceOf[T#MethodLocalObject$2.type]() - }; + final <artifact> private[this] def MethodLocalObject$lzycompute$1(barParam$1: String, MethodLocalObject$module$1: scala.runtime.LazyRef): T#MethodLocalObject$2.type = MethodLocalObject$module$1.synchronized[T#MethodLocalObject$2.type](if (MethodLocalObject$module$1.initialized()) + MethodLocalObject$module$1.value().$asInstanceOf[T#MethodLocalObject$2.type]() + else + MethodLocalObject$module$1.initialize(new T#MethodLocalObject$2.type(T.this, barParam$1)).$asInstanceOf[T#MethodLocalObject$2.type]()); + final private[this] def MethodLocalObject$1(barParam$1: String, MethodLocalObject$module$1: scala.runtime.LazyRef): T#MethodLocalObject$2.type = if (MethodLocalObject$module$1.initialized()) + MethodLocalObject$module$1.value().$asInstanceOf[T#MethodLocalObject$2.type]() + else + T.this.MethodLocalObject$lzycompute$1(barParam$1, MethodLocalObject$module$1); final <artifact> private[this] def $anonfun$tryy$1(tryyParam$1: String, tryyLocal$1: runtime.ObjectRef): Unit = try { tryyLocal$1.elem = tryyParam$1 } finally () diff --git a/test/files/run/local_obj.scala b/test/files/run/local_obj.scala new file mode 100644 index 0000000000..25123f7078 --- /dev/null +++ b/test/files/run/local_obj.scala @@ -0,0 +1,9 @@ +class C { + val z = 2 + def mod = { object x { val y = z } ; x.y } +} + +object Test extends App { + val c = new C + assert(c.mod == c.z, s"${c.mod} != ${c.z}") +} diff --git a/test/files/run/t6028.check b/test/files/run/t6028.check index d6cc452bbf..05634fa8eb 100644 --- a/test/files/run/t6028.check +++ b/test/files/run/t6028.check @@ -15,7 +15,7 @@ package <empty> { } }; def bar(barParam: Int): Object = { - @volatile var MethodLocalObject$module: runtime.VolatileObjectRef = scala.runtime.VolatileObjectRef.zero(); + lazy <artifact> val MethodLocalObject$module: scala.runtime.LazyRef = new scala.runtime.LazyRef(); T.this.MethodLocalObject$1(barParam, MethodLocalObject$module) }; def tryy(tryyParam: Int): Function0 = { @@ -54,12 +54,14 @@ package <empty> { <synthetic> <stable> <artifact> def $outer(): T = MethodLocalObject$2.this.$outer; <synthetic> <stable> <artifact> def $outer(): T = MethodLocalObject$2.this.$outer }; - final <stable> private[this] def MethodLocalObject$1(barParam$1: Int, MethodLocalObject$module$1: runtime.VolatileObjectRef): T#MethodLocalObject$2.type = { - if (MethodLocalObject$module$1.elem.$asInstanceOf[T#MethodLocalObject$2.type]().eq(null)) - T.this.synchronized[Unit](if (MethodLocalObject$module$1.elem.$asInstanceOf[T#MethodLocalObject$2.type]().eq(null)) - MethodLocalObject$module$1.elem = new T#MethodLocalObject$2.type(T.this, barParam$1)); - MethodLocalObject$module$1.elem.$asInstanceOf[T#MethodLocalObject$2.type]() - }; + final <artifact> private[this] def MethodLocalObject$lzycompute$1(barParam$1: Int, MethodLocalObject$module$1: scala.runtime.LazyRef): T#MethodLocalObject$2.type = MethodLocalObject$module$1.synchronized[T#MethodLocalObject$2.type](if (MethodLocalObject$module$1.initialized()) + MethodLocalObject$module$1.value().$asInstanceOf[T#MethodLocalObject$2.type]() + else + MethodLocalObject$module$1.initialize(new T#MethodLocalObject$2.type(T.this, barParam$1)).$asInstanceOf[T#MethodLocalObject$2.type]()); + final private[this] def MethodLocalObject$1(barParam$1: Int, MethodLocalObject$module$1: scala.runtime.LazyRef): T#MethodLocalObject$2.type = if (MethodLocalObject$module$1.initialized()) + MethodLocalObject$module$1.value().$asInstanceOf[T#MethodLocalObject$2.type]() + else + T.this.MethodLocalObject$lzycompute$1(barParam$1, MethodLocalObject$module$1); @SerialVersionUID(value = 0) final <synthetic> class $anonfun$tryy$1 extends scala.runtime.AbstractFunction0$mcV$sp with Serializable { def <init>($outer: T, tryyParam$1: Int, tryyLocal$1: runtime.IntRef): <$anon: Function0> = { $anonfun$tryy$1.super.<init>(); diff --git a/test/files/run/t9697.check b/test/files/run/t9697.check new file mode 100644 index 0000000000..2a4f01c14f --- /dev/null +++ b/test/files/run/t9697.check @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..eb8e44f8fc --- /dev/null +++ b/test/files/run/t9697.scala @@ -0,0 +1,204 @@ +object log { + val b = new collection.mutable.StringBuilder + def apply(s: Any): Unit = b.append(s) + def check(s: String) = { + val bs = b.toString + assert(s == bs, bs) + b.clear() + } +} + +package t9697 { + abstract class WA extends DelayedInit { + override def delayedInit(x: => Unit): Unit = x + val waField = "4" + } + + class C { + def b(s: String) = log(s) + val cField = "1" + + { + val dummyLocal = "2" + new WA { + val anonField = "3" + b(cField) + b(dummyLocal) + b(anonField) + b(waField) + } + } + } +} + +package sd229 { + class Broken { + def is(ee: AnyRef) = { + new Delayed { + log(ee) + } + } + } + + class Delayed extends DelayedInit { + def delayedInit(x: => Unit): Unit = x + } +} + + +// already fixed in 2.11.8, crashes in 2.10.6 +package t4683a { + class A { log("a") } + class B { log("b") } + class Bug extends DelayedInit { + log("bug") + def foo(a: A): B = new B + def delayedInit(init: => Unit): Unit = init + } +} + +// already fixed in 2.12.0-RC1, crashes in 2.11.8 +package t4683b { + class Entity extends DelayedInit { + def delayedInit(x: => Unit): Unit = x + + class Field + + protected def EntityField[T <: Entity: reflect.ClassTag] = new Field + + def find[T <: Entity: reflect.ClassTag] { + Nil.map(dbo => { + class EntityHolder extends Entity { + val entity = EntityField[T] + } + }) + log("find") + } + } +} + +package t4683c { + trait T extends DelayedInit { + def delayedInit(body: => Unit) = { + log("init") + body + } + } +} + +package t4683d { + class C extends DelayedInit { + def delayedInit(body: => Unit): Unit = body + } + class Injector { + def test: Object = { + val name = "k" + class crash extends C { + log(name) + } + new crash() + } + } +} + +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") + + new sd229.Broken().is("hi") + log.check("hi") + + val a: t4683a.A = new t4683a.A + var b: t4683a.B = null + new t4683a.Bug { + val b = foo(a) + } + log.check("abugb") + + new t4683b.Entity().find[t4683b.Entity] + log.check("find") + + val f = (p1: Int) => new t4683c.T { log(p1) } + f(5) + log.check("init5") + + 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) +} diff --git a/test/files/run/t9920.scala b/test/files/run/t9920.scala new file mode 100644 index 0000000000..5dc32e99b7 --- /dev/null +++ b/test/files/run/t9920.scala @@ -0,0 +1,17 @@ +class C0 +trait T { self: C0 => + def test = { + object Local + + class C1 { + Local + } + new C1() + } +} + +object Test extends C0 with T { + def main(args: Array[String]): Unit = { + test + } +} diff --git a/test/files/run/t9920b.scala b/test/files/run/t9920b.scala new file mode 100644 index 0000000000..fab196b669 --- /dev/null +++ b/test/files/run/t9920b.scala @@ -0,0 +1,17 @@ +class C0 +trait T { + def test = { + object Local + + class C1 { + Local + } + new C1() + } +} + +object Test extends C0 with T { + def main(args: Array[String]): Unit = { + test + } +} diff --git a/test/files/run/t9920c.scala b/test/files/run/t9920c.scala new file mode 100644 index 0000000000..9541dc650a --- /dev/null +++ b/test/files/run/t9920c.scala @@ -0,0 +1,21 @@ +class C0 +trait T { self: C0 => + def test = { + object Local + + class C2 { + class C1 { + Local + } + T.this.toString + new C1 + } + new C2() + } +} + +object Test extends C0 with T { + def main(args: Array[String]): Unit = { + test + } +} diff --git a/test/files/run/t9920d.scala b/test/files/run/t9920d.scala new file mode 100644 index 0000000000..debc99e199 --- /dev/null +++ b/test/files/run/t9920d.scala @@ -0,0 +1,14 @@ +class C { object O } +trait T { _: C => + def foo { + class D { O } + new D + } +} + + +object Test extends C with T { + def main(args: Array[String]): Unit = { + foo + } +} |