Box inline class return value in lambdas (including suspend lambdas)

This commit is contained in:
Dmitry Petrov
2020-04-08 12:28:17 +03:00
parent 59b72b3156
commit 9615b20e5d
22 changed files with 691 additions and 18 deletions
@@ -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
}
@@ -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
}