Files
kotlin-fork/compiler/testData/codegen/box/funInterface/kt44827_funInterface.kt
T
Alexander Udalov 628d75c7cd JVM: fix EnclosingMethod information for SAMs in inline lambdas
Pass parentContext to SamWrapperCodegen from the outside instead of
using the one from parentCodegen. The difference is that in case of an
inline lambda, we're creating an InlineLambdaContext whose parent is a
ClosureContext, but the codegen for that lambda has that latter
ClosureContext as its context. So the getNonInlineOuterContext call in
SamWrapperCodegen.generateInnerClassInformation wasn't able to identify
that this is a context of a lambda that needs to be skipped, and
generated it as EnclosingMethod, which caused Java reflection to fail
because once that lambda was inlined, it was removed and thus didn't
make it to runtime.

 #KT-44827 Fixed
2021-03-09 11:43:11 +01:00

23 lines
395 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_RUNTIME
fun interface J {
operator fun invoke(): String
}
fun invoke(j: J): String {
// Check that there's something sensible in the EnclosingMethod; crashes if it's not the case.
j.javaClass.enclosingMethod
return j()
}
class A(val result: String)
fun box(): String {
var a = A("OK")
return 42.let {
invoke(a::result)
}
}