Box inline class returned from suspend lambda non-locally

All inline classes should be boxed coming in and out of lambdas,
however, if the inline class was returned non-locally, it was not boxed.
This change fixes the issue in Old JVM BE.
 #KT-41194 In progress
This commit is contained in:
Ilmir Usmanov
2020-10-16 01:50:30 +02:00
parent c1765a5306
commit 70a4ed3ebc
10 changed files with 85 additions and 4 deletions
@@ -0,0 +1,31 @@
// WITH_RUNTIME
// IGNORE_BACKEND: JVM_IR, JS_IR
// IGNORE_BACKEND_FIR: JVM_IR
import kotlin.coroutines.*
fun <T> builder(c: suspend () -> T): T {
var res: T? = null
c.startCoroutine(Continuation(EmptyCoroutineContext) {
res = it.getOrThrow()
})
return res!!
}
suspend fun <T> runSuspend(c: suspend () -> T): T {
return c()
}
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")
suspend fun foo(): Result<String> = runSuspend {
run { return@runSuspend Result.failure<String>(RuntimeException("OK")) }
}
fun box(): String {
return try {
builder { foo() }.getOrThrow()
"FAIL"
} catch (e: RuntimeException) {
e.message!!
}
}