Files
kotlin-fork/compiler/testData/codegen/boxInline/enclosingInfo/inlineChain.kt
T
pyos ce0fb662c0 JVM_IR: fold inline lambdas when computing OUTERCLASS
so that the enclosing method of objects defined inside lambdas is the
one they are declared in.

Note that this does not fix *all* enclosingInfo tests because JVM_IR
currently follows the KT-28064 proposal, i.e. does not regenerate
objects defined inside lambdas under any circumstances. For example,
this causes test boxInline/enclosingInfo/inlineChain2.kt to fail because
the enclosing method of objects is _2Kt.box instead of (non-existent in
source code) `_2Kt$box$inlined$call$1.invoke` or whatever. What's more
important is that OUTERCLASS no longer points to a non-existent
`box$lambda-N` and therefore `.enclosingMethod` no longer throws.
2019-11-12 12:44:46 +01:00

39 lines
906 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// FILE: 1.kt
// WITH_REFLECT
package test
inline fun <R> call(s: () -> R) = s()
inline fun test(crossinline z: () -> String) = { z() }
// FILE: 2.kt
import test.*
fun box(): String {
val res = call {
test { "OK" }
}
var enclosingMethod = res.javaClass.enclosingMethod
if (enclosingMethod?.name != "box") return "fail 1: ${enclosingMethod?.name}"
var enclosingClass = res.javaClass.enclosingClass
if (enclosingClass?.name != "_2Kt") return "fail 2: ${enclosingClass?.name}"
val res2 = call {
call {
test { "OK" }
}
}
enclosingMethod = res2.javaClass.enclosingMethod
if (enclosingMethod?.name != "box") return "fail 1: ${enclosingMethod?.name}"
enclosingClass = res2.javaClass.enclosingClass
if (enclosingClass?.name != "_2Kt") return "fail 2: ${enclosingClass?.name}"
return res2()
}