JVM_IR indy-SAM conversions: use old scheme for suspend funs

KT-44278 KT-26060 KT-42621
This commit is contained in:
Dmitry Petrov
2021-01-26 14:40:55 +03:00
parent 1f16b96796
commit 4da2f3d9d4
9 changed files with 88 additions and 17 deletions
@@ -0,0 +1,42 @@
// !LANGUAGE: +SuspendFunctionsInFunInterfaces +JvmIrEnabledByDefault
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.*
var c: Continuation<Unit>? = null
suspend fun suspendMe() = suspendCoroutine<Unit> { continuation ->
c = continuation
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(object: Continuation<Unit> {
override val context = EmptyCoroutineContext
override fun resumeWith(result: Result<Unit>) {
result.getOrThrow()
}
})
}
fun interface SuspendFoo {
suspend fun foo()
}
fun box(): String {
var test = ""
val lambda = SuspendFoo {
suspendMe()
test += "O"
suspendMe()
test += "K"
}
builder {
lambda.foo()
}
c?.resume(Unit)
c?.resume(Unit)
return test
}