blob: b674b2863380a926429762b94999e915cba64c2e [file]
// WITH_STDLIB
// WITH_COROUTINES
import kotlin.contracts.*
import kotlin.coroutines.*
import helpers.*
@ExperimentalContracts
public fun <T> runBlocking(block: suspend () -> T): T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
var res: T? = null
suspend {
res = block()
}.startCoroutine(EmptyContinuation)
return res!!
}
sealed class S {
class Z : S() {
fun f(): String = "OK"
}
}
val z: S = S.Z()
@OptIn(ExperimentalContracts::class)
fun box(): String = test()
@ExperimentalContracts
fun test(): String = when (val w = z) {
is S.Z -> runBlocking { w.f() }
}