Files
kotlin-fork/compiler/testData/codegen/box/closures/refsAreSerializable.kt
T
Alexander Udalov cd9209a7ee JVM: enable -Xlambdas=class in some codegen tests
Most of these tests check the specific structure of lambdas when they
are generated as classes, and they start to fail once invokedynamic
lambdas are enabled by default.
2023-04-28 21:34:19 +00:00

36 lines
790 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_STDLIB
import java.io.*
fun box(): String {
var o = ""
var b = 1.toByte()
var d = 1.0
var f = 1.0f
var i = 1
var j = 1L
var s = 1.toShort()
var c = '1'
var z = true
val lambda = @JvmSerializableLambda fun(): String {
o = "OK"
b++; d++; f++; i++; j++; s++; c++
z = false
return "$o $b $d $f $i $j $s $c $z"
}
val baos = ByteArrayOutputStream()
val oos = ObjectOutputStream(baos)
oos.writeObject(lambda)
oos.close()
val bais = ByteArrayInputStream(baos.toByteArray())
val ois = ObjectInputStream(bais)
val result = (ois.readObject() as () -> String)()
ois.close()
return if (result == "OK 2 2.0 2.0 2 2 2 2 false") "OK" else "Fail: $result"
}