diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2016-06-06 13:34:18 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-06-06 13:34:18 +1000 |
commit | 3bb735823f6815002895b1a335c6d105ddbe3e9e (patch) | |
tree | 5136e824612af0aa0a11675845713fd8a5101a70 /test | |
parent | 361f3f1540c755e36aaed22484924bb44eabc83b (diff) | |
parent | f07019ffa56ec2dfab8ab0d9a83133005761a877 (diff) | |
download | scala-3bb735823f6815002895b1a335c6d105ddbe3e9e.tar.gz scala-3bb735823f6815002895b1a335c6d105ddbe3e9e.tar.bz2 scala-3bb735823f6815002895b1a335c6d105ddbe3e9e.zip |
Merge pull request #5099 from retronym/ticket/9390
SI-9390 Emit local defs that don't capture this as static
Diffstat (limited to 'test')
-rw-r--r-- | test/files/jvm/t9105.check | 14 | ||||
-rw-r--r-- | test/files/run/t5652.check | 6 | ||||
-rw-r--r-- | test/files/run/t5652b.check | 4 | ||||
-rw-r--r-- | test/files/run/t5652c.check | 4 | ||||
-rw-r--r-- | test/files/run/t9390.scala | 67 | ||||
-rw-r--r-- | test/files/run/t9390b.scala | 31 | ||||
-rw-r--r-- | test/files/run/t9390c.scala | 21 | ||||
-rw-r--r-- | test/files/run/t9390d.scala | 12 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala | 4 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala | 2 |
10 files changed, 143 insertions, 22 deletions
diff --git a/test/files/jvm/t9105.check b/test/files/jvm/t9105.check index 48439ee004..9447e0cf29 100644 --- a/test/files/jvm/t9105.check +++ b/test/files/jvm/t9105.check @@ -1,18 +1,8 @@ -#partest -Ydelambdafy:inline -(class C$$anonfun$1$A$1,class C$$anonfun$1,null) -(class C$$anonfun$1$B$1,class C$$anonfun$1,private final java.lang.Object C$$anonfun$1.m$1()) -(class C$$anonfun$1$C$1,class C$$anonfun$1,null) -(class C$$anonfun$1$$anonfun$2$D$1,class C$$anonfun$1$$anonfun$2,null) -(class C$$anonfun$met$1$E$1,class C$$anonfun$met$1,null) -(class C$$anonfun$met$1$F$1,class C$$anonfun$met$1,private final java.lang.Object C$$anonfun$met$1.m$2()) -(class C$$anonfun$met$1$G$1,class C$$anonfun$met$1,null) -(class C$$anonfun$met$1$$anonfun$3$H$1,class C$$anonfun$met$1$$anonfun$3,null) -#partest !-Ydelambdafy:inline (class C$A$1,class C,null) -(class C$B$1,class C,private final java.lang.Object C.m$1()) +(class C$B$1,class C,private static final java.lang.Object C.m$1()) (class C$C$1,class C,null) (class C$D$1,class C,null) (class C$E$1,class C,public scala.Function0 C.met()) -(class C$F$1,class C,private final java.lang.Object C.m$2()) +(class C$F$1,class C,private static final java.lang.Object C.m$2()) (class C$G$1,class C,public scala.Function0 C.met()) (class C$H$1,class C,public scala.Function0 C.met()) diff --git a/test/files/run/t5652.check b/test/files/run/t5652.check index a0fb6fe9b4..7c65ba6698 100644 --- a/test/files/run/t5652.check +++ b/test/files/run/t5652.check @@ -1,7 +1,7 @@ -public default int T1.T1$$g$1() public default int T1.f0() public default void T1.$init$() -public final int A1.A1$$g$2() +public static int T1.T1$$g$1() public int A1.f1() -public final int A2.A2$$g$1() +public static final int A1.A1$$g$2() public int A2.f2() +public static final int A2.A2$$g$1() diff --git a/test/files/run/t5652b.check b/test/files/run/t5652b.check index ca9d0a74f0..0f4290796f 100644 --- a/test/files/run/t5652b.check +++ b/test/files/run/t5652b.check @@ -1,4 +1,4 @@ -private final int A1.g$1() +private static final int A1.g$1() public int A1.f1() -private final int A2.g$1() +private static final int A2.g$1() public int A2.f2() diff --git a/test/files/run/t5652c.check b/test/files/run/t5652c.check index 3b889e066d..5a6d535f02 100644 --- a/test/files/run/t5652c.check +++ b/test/files/run/t5652c.check @@ -1,6 +1,6 @@ -public final int A1.A1$$g$1() -public final int A1.A1$$g$2() public int A1.f1() public int A1.f2() +public static final int A1.A1$$g$1() +public static final int A1.A1$$g$2() 1 2 diff --git a/test/files/run/t9390.scala b/test/files/run/t9390.scala new file mode 100644 index 0000000000..8d7e1be557 --- /dev/null +++ b/test/files/run/t9390.scala @@ -0,0 +1,67 @@ +class C { + def methodLift1 = { + def isEven(c: Int) = c % 2 == 0 + val f: Int => Boolean = isEven + f + } + def methodLift2 = { + def isEven(c: Int) = c % 2 == 0 + def isEven0(c: Int) = isEven(c) + val f: Int => Boolean = isEven0 + f + } + + def methodLift3 = { + def isEven(c: Int) = {toString; c % 2 == 0} + def isEven0(c: Int) = isEven(c) + val f: Int => Boolean = isEven0 + f + } +} + +object Test { + def main(args: Array[String]): Unit = { + val c = new C + + { + val f = c.methodLift1 + assert(f(0)) + assert(!f(1)) + val f1 = serializeDeserialize(f) + assert(f1(0)) + assert(!f1(1)) + } + + + { + val f = c.methodLift2 + assert(f(0)) + assert(!f(1)) + val f1 = serializeDeserialize(f) + assert(f1(0)) + assert(!f1(1)) + } + + { + val f = c.methodLift3 + assert(f(0)) + assert(!f(1)) + try { + serializeDeserialize(this) + assert(false) + } catch { + case _: java.io.NotSerializableException => + // expected, the closure in methodLift3 must capture C which is not serializable + } + } + } + + def serializeDeserialize[T <: AnyRef](obj: T): T = { + import java.io._ + val buffer = new ByteArrayOutputStream + val out = new ObjectOutputStream(buffer) + out.writeObject(obj) + val in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray)) + in.readObject.asInstanceOf[T] + } +} diff --git a/test/files/run/t9390b.scala b/test/files/run/t9390b.scala new file mode 100644 index 0000000000..439e21e0a0 --- /dev/null +++ b/test/files/run/t9390b.scala @@ -0,0 +1,31 @@ +class C { // C is not serializable + def foo = (x: Int) => (y: Int) => x + y + def bar = (x: Int) => (y: Int) => {toString; x + y} +} + +object Test { + def main(args: Array[String]): Unit = { + val c = new C + val f = c.foo + assert(f(1)(2) == 3) + val f1 = serializeDeserialize(f) + assert(f1(1)(2) == 3) + + try { + serializeDeserialize(c.bar) + assert(false) + } catch { + case _: java.io.NotSerializableException => + // expected, lambda transitively refers to this + } + } + + def serializeDeserialize[T <: AnyRef](obj: T): T = { + import java.io._ + val buffer = new ByteArrayOutputStream + val out = new ObjectOutputStream(buffer) + out.writeObject(obj) + val in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray)) + in.readObject.asInstanceOf[T] + } +} diff --git a/test/files/run/t9390c.scala b/test/files/run/t9390c.scala new file mode 100644 index 0000000000..db39da57cd --- /dev/null +++ b/test/files/run/t9390c.scala @@ -0,0 +1,21 @@ +class C { // C is not serializable + def foo = { + { (x: Any) => new Object {} } + } +} +object Test { + def main(args: Array[String]): Unit = { + val c = new C + val f = c.foo + val f1 = serializeDeserialize(f) + } + + def serializeDeserialize[T <: AnyRef](obj: T): T = { + import java.io._ + val buffer = new ByteArrayOutputStream + val out = new ObjectOutputStream(buffer) + out.writeObject(obj) + val in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray)) + in.readObject.asInstanceOf[T] + } +} diff --git a/test/files/run/t9390d.scala b/test/files/run/t9390d.scala new file mode 100644 index 0000000000..3c5de3abf7 --- /dev/null +++ b/test/files/run/t9390d.scala @@ -0,0 +1,12 @@ +class C { // C is not serializable + def foo: () => Any = { + { () => class UseOuterInConstructor { C.this.toString }; new UseOuterInConstructor : Any} + } +} +object Test { + def main(args: Array[String]): Unit = { + val c = new C + val f = c.foo + f() // Doesn't NPE, as we didn't elide the outer instance in the constructor call. + } +} diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala index 6161dc7b73..024cf0c416 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala @@ -113,7 +113,7 @@ class InlineWarningTest extends BytecodeTesting { val warn = """M::f()I is annotated @inline but could not be inlined: - |The callee M::f()I contains the instruction INVOKESPECIAL M.nested$1 ()I + |The callee M::f()I contains the instruction INVOKESTATIC M.nested$1 ()I |that would cause an IllegalAccessError when inlined into class N""".stripMargin var c = 0 @@ -140,7 +140,7 @@ class InlineWarningTest extends BytecodeTesting { val warn = """M::f(Lscala/Function1;)I could not be inlined: - |The callee M::f(Lscala/Function1;)I contains the instruction INVOKESPECIAL M.nested$1 ()I + |The callee M::f(Lscala/Function1;)I contains the instruction INVOKESTATIC M.nested$1 ()I |that would cause an IllegalAccessError when inlined into class N""".stripMargin var c = 0 diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala index 7234659a1d..02cd632af1 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala @@ -1141,7 +1141,7 @@ class InlinerTest extends BytecodeTesting { val warn = """C::h()I is annotated @inline but could not be inlined: - |The callee C::h()I contains the instruction INVOKESPECIAL C.f$1 ()I + |The callee C::h()I contains the instruction INVOKESTATIC C.f$1 ()I |that would cause an IllegalAccessError when inlined into class D.""".stripMargin val List(c, d) = compile(code, allowMessage = _.msg contains warn) |