Files
kotlin-fork/compiler/testData/codegen/box/closures/kt23881.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

32 lines
761 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM
// LAMBDAS: CLASS
// WITH_STDLIB
class ShouldBeCaptured
class ShouldNOTBeCaptured
class ClassWithCallback {
var someCallback: (() -> Unit)? = null
fun checkFields(): String {
for (field in someCallback!!.javaClass.declaredFields) {
val value = field.get(someCallback!!)
if (value is ShouldNOTBeCaptured) throw AssertionError("Leaked value")
}
return "OK"
}
}
fun box(): String {
val toCapture = ShouldBeCaptured()
val notToCapture = ShouldNOTBeCaptured()
val classWithCallback = ClassWithCallback()
classWithCallback.apply {
someCallback = { toCapture }
notToCapture
}
return classWithCallback.checkFields()
}