Box inline class return value in lambdas (including suspend lambdas)
This commit is contained in:
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
|
||||
import helpers.*
|
||||
import kotlin.coroutines.*
|
||||
|
||||
inline class R(val x: Any)
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
suspend fun <T> call(fn: suspend () -> T) = fn()
|
||||
|
||||
fun useR(r: R) = if (r.x == "OK") "OK" else "fail: $r"
|
||||
|
||||
suspend fun ok() = R("OK")
|
||||
|
||||
fun box(): String {
|
||||
var res: String = "fail"
|
||||
builder {
|
||||
res = useR(call(::ok))
|
||||
}
|
||||
return res
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
|
||||
import helpers.*
|
||||
import kotlin.coroutines.*
|
||||
|
||||
inline class R(val x: Any)
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
suspend fun <T> call(fn: suspend () -> T) = fn()
|
||||
|
||||
fun useR(r: R) = if (r.x == "OK") "OK" else "fail: $r"
|
||||
|
||||
fun box(): String {
|
||||
var res: String = "fail"
|
||||
builder {
|
||||
res = useR(call { R("OK") })
|
||||
}
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user