summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
Diffstat (limited to 'test/files')
-rw-r--r--test/files/run/t720.scala48
-rw-r--r--test/files/run/t9365.check2
-rw-r--r--test/files/run/t9365.scala18
-rw-r--r--test/files/run/t9403.flags1
-rw-r--r--test/files/run/t9403/C_1.scala5
-rw-r--r--test/files/run/t9403/Test_2.scala29
-rw-r--r--test/files/run/t9422.scala11
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))
+ }
+}