diff options
author | Seth Tisue <seth@tisue.net> | 2015-08-05 14:58:35 -0700 |
---|---|---|
committer | Seth Tisue <seth@tisue.net> | 2015-08-05 14:58:35 -0700 |
commit | 2fe5159ad6b4c672db5f967cebe9d1ac98dede9f (patch) | |
tree | 406db7c5db708d03891b463613e3ecd8f210ce19 /test/files | |
parent | 462e22d2f25bb9432c5a1e7bf20f391e6424f7a9 (diff) | |
parent | ecf9128d8bf7a965492f0b714876650bba66b040 (diff) | |
download | scala-2fe5159ad6b4c672db5f967cebe9d1ac98dede9f.tar.gz scala-2fe5159ad6b4c672db5f967cebe9d1ac98dede9f.tar.bz2 scala-2fe5159ad6b4c672db5f967cebe9d1ac98dede9f.zip |
Merge pull request #4687 from adriaanm/merge-2.11.x-aug-5
Merge 2.11.x aug 5 [ci: last-only]
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/t720.scala | 48 | ||||
-rw-r--r-- | test/files/run/t9365.check | 2 | ||||
-rw-r--r-- | test/files/run/t9365.scala | 18 | ||||
-rw-r--r-- | test/files/run/t9403.flags | 1 | ||||
-rw-r--r-- | test/files/run/t9403/C_1.scala | 5 | ||||
-rw-r--r-- | test/files/run/t9403/Test_2.scala | 29 | ||||
-rw-r--r-- | test/files/run/t9422.scala | 11 |
7 files changed, 114 insertions, 0 deletions
diff --git a/test/files/run/t720.scala b/test/files/run/t720.scala new file mode 100644 index 0000000000..a5cb2495cf --- /dev/null +++ b/test/files/run/t720.scala @@ -0,0 +1,48 @@ +class Lazy(f: => Int) { + lazy val get: Int = f +} + +class UsedLater(f: => Int) { + lazy val get: Int = f + def other = f +} + +class TransientLazy(f: => Int) { + @transient + lazy val get: Int = f +} + +object Test { + def main(args: Array[String]): Unit = { + testLazy() + testUsedLater() + } + + def testLazy() { + val o = new Lazy("".length) + val f = classOf[Lazy].getDeclaredField("f") + f.setAccessible(true) + assert(f.get(o) != null) + o.get + assert(f.get(o) == null) + } + + def testUsedLater() { + val o = new UsedLater("".length) + val f = classOf[UsedLater].getDeclaredField("f") + f.setAccessible(true) + assert(f.get(o) != null) + o.get + assert(f.get(o) != null) + } + + def testTransientLazy() { + val o = new TransientLazy("".length) + val f = classOf[TransientLazy].getDeclaredField("f") + f.setAccessible(true) + assert(f.get(o) != null) + o.get + assert(f.get(o) != null) // SI-9365 + } +} + diff --git a/test/files/run/t9365.check b/test/files/run/t9365.check new file mode 100644 index 0000000000..0d55bed3a3 --- /dev/null +++ b/test/files/run/t9365.check @@ -0,0 +1,2 @@ +foo +foo diff --git a/test/files/run/t9365.scala b/test/files/run/t9365.scala new file mode 100644 index 0000000000..0c4477dda9 --- /dev/null +++ b/test/files/run/t9365.scala @@ -0,0 +1,18 @@ +class Test(x: => Object) extends Serializable { + @transient lazy val foo = x +} + +object Test { + def main(args: Array[String]): Unit = { + import java.io._ + val t = new Test("foo") + println(t.foo) + val baos = new ByteArrayOutputStream + val dos = new ObjectOutputStream(baos) + dos.writeObject(t) + dos.close() + val dis = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())) + val t1 = dis.readObject().asInstanceOf[Test] + println(t1.foo) // was NPE + } +} diff --git a/test/files/run/t9403.flags b/test/files/run/t9403.flags new file mode 100644 index 0000000000..307668060c --- /dev/null +++ b/test/files/run/t9403.flags @@ -0,0 +1 @@ +-Ybackend:GenASM -optimize diff --git a/test/files/run/t9403/C_1.scala b/test/files/run/t9403/C_1.scala new file mode 100644 index 0000000000..439af1a386 --- /dev/null +++ b/test/files/run/t9403/C_1.scala @@ -0,0 +1,5 @@ +package p +class C { + @inline final def f(x: Int): Long = 10L / (if (x < 0) -2 else 2) + @inline final def g(x: Int): Long = 3000L / (if (x < 0) -300 else 300) +} diff --git a/test/files/run/t9403/Test_2.scala b/test/files/run/t9403/Test_2.scala new file mode 100644 index 0000000000..fb2777b9a8 --- /dev/null +++ b/test/files/run/t9403/Test_2.scala @@ -0,0 +1,29 @@ +import p.C +import scala.tools.asm.Opcodes +import scala.tools.partest.BytecodeTest +import scala.tools.partest.ASMConverters._ + + +object Test extends BytecodeTest { + def foo(c: C, x: Int) = c.f(x) + def goo(c: C, x: Int) = c.g(x) + + def has(i: Instruction, c: String, m: String) = { + val cls = loadClassNode(c) + val mth = convertMethod(getMethod(cls, m)) + assert(mth.instructions.contains(i)) + } + + def show(): Unit = { + assert(foo(new C, -2) == -5L) + assert(goo(new C, -2) == -10L) + + val bipush2 = IntOp(Opcodes.BIPUSH, -2) + has(bipush2, "p.C", "f") + has(bipush2, "Test$", "foo") + + val sipush300 = IntOp(Opcodes.SIPUSH, -300) + has(sipush300, "p.C", "g") + has(sipush300, "Test$", "goo") + } +} diff --git a/test/files/run/t9422.scala b/test/files/run/t9422.scala new file mode 100644 index 0000000000..5ca2e8daaa --- /dev/null +++ b/test/files/run/t9422.scala @@ -0,0 +1,11 @@ +class Test(val x: Long) { + def sameDirection(y: Long): Boolean = + (y == 0 || x == 0 || ((y > 0) == (x > 0))) +} + +object Test { + def main(args: Array[String]) { + val b = new Test(1L) + assert(!b.sameDirection(-1L)) + } +} |