Files
kotlin/compiler/testData/codegen/box/coroutines/controllerAccessFromInnerLambda.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

47 lines
946 B
Kotlin
Vendored

// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
// WITH_COROUTINES
// COMMON_COROUTINES_TEST
import helpers.*
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
class Controller {
var result = false
suspend fun suspendHere(): String = suspendCoroutineUninterceptedOrReturn { x ->
x.resume("OK")
COROUTINE_SUSPENDED
}
fun foo() {
result = true
}
}
fun builder(c: suspend Controller.() -> Unit) {
val controller = Controller()
c.startCoroutine(controller, EmptyContinuation)
if (!controller.result) throw RuntimeException("fail")
}
fun noinlineRun(block: () -> Unit) {
block()
}
fun box(): String {
builder {
if (suspendHere() != "OK") {
throw RuntimeException("fail 1")
}
noinlineRun {
foo()
}
if (suspendHere() != "OK") {
throw RuntimeException("fail 2")
}
}
return "OK"
}