Files
kotlin/compiler/testData/codegen/box/coroutines/beginWithException.kt
Roman Artemev c62e4b4fcf [JS IR BE] Support coroutines
* Move FinallyBlockLowering to common part
* Fix catching of dynamic exception
* Fix bridges for suspend functions
* Disable explicit cast to Unit
* Run lowering per module
* Update some test data
2018-08-08 18:33:39 +03:00

43 lines
941 B
Kotlin
Vendored

// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
// WITH_COROUTINES
// COMMON_COROUTINES_TEST
import helpers.*
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
suspend fun suspendHere(): Any = suspendCoroutineUninterceptedOrReturn { x -> }
fun builder(c: suspend () -> Unit) {
var exception: Throwable? = null
c.createCoroutine(object : ContinuationAdapter<Unit>() {
override val context = EmptyCoroutineContext
override fun resume(data: Unit) {
}
override fun resumeWithException(e: Throwable) {
exception = e
}
}).resumeWithException(RuntimeException("OK"))
if (exception?.message != "OK") {
throw RuntimeException("Unexpected result: ${exception?.message}")
}
}
fun box(): String {
var result = "OK"
builder {
suspendHere()
result = "fail 1"
}
builder {
result = "fail 2"
}
return result
}