[box-tests] Added a bunch of tests on local objects in inline lambdas

This commit is contained in:
Igor Chevdar
2022-08-04 20:39:39 +03:00
committed by Space
parent 7090a2716a
commit e38f02b53a
17 changed files with 343 additions and 0 deletions
@@ -0,0 +1,36 @@
// NO_CHECK_LAMBDA_INLINING
// IGNORE_BACKEND: JVM, WASM
// IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_MULTI_MODULE_OLD_AGAINST_IR
import kotlin.IllegalStateException
// FILE: 1.kt
inline fun <T> mrun(block: () -> T) = block()
inline fun <T> mrunTwice(block: () -> T) : T {
val first = block()
val second = block()
if (first!!::class != second!!::class)
throw IllegalStateException("${first!!::class} != ${second!!::class}")
return first
}
inline fun <T> T.noop() = this
// FILE: 2.kt
fun bar(o: String): String {
val callable = mrun {
fun localAnonymousFun(k: String): String {
fun localAnonymousFunLevel2() = mrunTwice {
object {
fun foo() = o + k
}
}
return localAnonymousFunLevel2().foo()
}
::localAnonymousFun
}.noop()
return callable("K")
}
fun box() = bar("O")
@@ -0,0 +1,34 @@
// NO_CHECK_LAMBDA_INLINING
// IGNORE_BACKEND: JVM, WASM
// IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_MULTI_MODULE_OLD_AGAINST_IR
import kotlin.IllegalStateException
// FILE: 1.kt
inline fun <T> mrun(noinline block: () -> T) = block()
inline fun <T> mrunTwice(block: () -> T) : T {
val first = block()
val second = block()
if (first!!::class != second!!::class)
throw IllegalStateException("${first!!::class} != ${second!!::class}")
return first
}
// FILE: 2.kt
fun bar(o: String): String {
val callable = mrun {
fun localAnonymousFun(k: String): String {
fun localAnonymousFunLevel2() = mrunTwice {
object {
fun foo() = o + k
}
}
return localAnonymousFunLevel2().foo()
}
::localAnonymousFun
}
return callable("K")
}
fun box() = bar("O")
@@ -0,0 +1,24 @@
// NO_CHECK_LAMBDA_INLINING
import kotlin.IllegalStateException
// FILE: 1.kt
inline fun <T> mrun2(noinline block: () -> T, block2: () -> Unit): T { block2(); return block() }
// FILE: 2.kt
fun bar(o: String): String {
val obj = mrun2(
{
object {
fun foo() = o + "K"
}
},
{
fun localFun() = 42
}
)
return obj.foo()
}
fun box() = bar("O")