From b0b5b09f90b84696695538a42e7b7ff36555c0f9 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Wed, 23 Sep 2015 15:11:01 +0200 Subject: Add $deserializeLambda$ when inlining an indyLambda into a class Fixes https://github.com/scala/scala-dev/issues/39 When inlining an indyLambda closure instantiation into a class, and the closure type is serializable, make sure that the target class has the synthetic `$deserializeLambda$` method. --- test/files/run/inlineAddDeserializeLambda.scala | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/files/run/inlineAddDeserializeLambda.scala (limited to 'test/files') diff --git a/test/files/run/inlineAddDeserializeLambda.scala b/test/files/run/inlineAddDeserializeLambda.scala new file mode 100644 index 0000000000..a6bafd0f49 --- /dev/null +++ b/test/files/run/inlineAddDeserializeLambda.scala @@ -0,0 +1,20 @@ +class C { @inline final def f: Int => Int = (x: Int) => x + 1 } + +object Test extends App { + import java.io._ + + def serialize(obj: AnyRef): Array[Byte] = { + val buffer = new ByteArrayOutputStream + val out = new ObjectOutputStream(buffer) + out.writeObject(obj) + buffer.toByteArray + } + def deserialize(a: Array[Byte]): AnyRef = { + val in = new ObjectInputStream(new ByteArrayInputStream(a)) + in.readObject + } + + def serializeDeserialize[T <: AnyRef](obj: T) = deserialize(serialize(obj)).asInstanceOf[T] + + assert(serializeDeserialize((new C).f).isInstanceOf[Function1[_, _]]) +} -- cgit v1.2.3