summaryrefslogtreecommitdiff
path: root/test/files/run/lambda-serialization.scala
diff options
context:
space:
mode:
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)