Files
kotlin-fork/compiler/testData/codegen/box/reflection/enclosing/classInLambda.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

25 lines
666 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// LAMBDAS: CLASS
// WITH_REFLECT
fun box(): String {
val lambda = {
class Z {}
Z()
}
val classInLambda = lambda()
val enclosingMethod = classInLambda.javaClass.getEnclosingMethod()
if (enclosingMethod?.getName() != "invoke") return "method: $enclosingMethod"
val enclosingClass = classInLambda.javaClass.getEnclosingClass()!!.getName()
if (enclosingClass != "ClassInLambdaKt\$box\$lambda\$1") return "enclosing class: $enclosingClass"
val declaringClass = classInLambda.javaClass.getDeclaringClass()
if (declaringClass != null) return "class has a declaring class"
return "OK"
}