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

26 lines
666 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// LAMBDAS: CLASS
// WITH_REFLECT
class C {
class D {
fun foo(): Any {
return {}
}
}
}
fun box(): String {
val javaClass = C.D().foo().javaClass
val enclosingMethod = javaClass.getEnclosingMethod()
if (enclosingMethod?.getName() != "foo") return "method: $enclosingMethod"
val enclosingClass = javaClass.getEnclosingClass()
if (enclosingClass?.getSimpleName() != "D") return "enclosing class: $enclosingClass"
val declaringClass = javaClass.getDeclaringClass()
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
return "OK"
}