summaryrefslogtreecommitdiff
path: root/test/files/run/lambda-serialization.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2016-03-17 11:56:14 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2016-03-26 22:54:10 -0700
commitf922f367d58b3ba6bbb4cb0864ce82c5cd6f7966 (patch)
tree18a9cf588cd9e6dbe0a3815258f4dede2af3c772 /test/files/run/lambda-serialization.scala
parent040c0434d456dd75a174147d8a0c4cab37266ba6 (diff)
downloadscala-f922f367d58b3ba6bbb4cb0864ce82c5cd6f7966.tar.gz
scala-f922f367d58b3ba6bbb4cb0864ce82c5cd6f7966.tar.bz2
scala-f922f367d58b3ba6bbb4cb0864ce82c5cd6f7966.zip
Additional SAM restrictions identified by Jason
Also test roundtripping serialization of a lambda that targets a SAM that's not FunctionN (it should make no difference).
Diffstat (limited to 'test/files/run/lambda-serialization.scala')
-rw-r--r--test/files/run/lambda-serialization.scala14
1 files changed, 13 insertions, 1 deletions
diff --git a/test/files/run/lambda-serialization.scala b/test/files/run/lambda-serialization.scala
index 46b26d7c5e..0eee1193d7 100644
--- a/test/files/run/lambda-serialization.scala
+++ b/test/files/run/lambda-serialization.scala
@@ -1,8 +1,11 @@
import java.io.{ByteArrayInputStream, ObjectInputStream, ObjectOutputStream, ByteArrayOutputStream}
+trait IntToString { def apply(i: Int): String }
+
object Test {
def main(args: Array[String]): Unit = {
- roundTrip
+ roundTrip()
+ roundTripIndySam()
}
def roundTrip(): Unit = {
@@ -22,6 +25,15 @@ object Test {
assert(serializeDeserialize(serializeDeserialize(specializedLambda)).apply(42) == 2)
}
+ // lambda targeting a SAM, not a FunctionN (should behave the same way)
+ def roundTripIndySam(): Unit = {
+ val lambda: IntToString = (x: Int) => "yo!" * x
+ val reconstituted1 = serializeDeserialize(lambda).asInstanceOf[IntToString]
+ val reconstituted2 = serializeDeserialize(reconstituted1).asInstanceOf[IntToString]
+ assert(reconstituted1.apply(2) == "yo!yo!")
+ assert(reconstituted1.getClass == reconstituted2.getClass)
+ }
+
def serializeDeserialize[T <: AnyRef](obj: T) = {
val buffer = new ByteArrayOutputStream
val out = new ObjectOutputStream(buffer)