Files
kotlin/compiler/testData/codegen/box/coroutines/emptyClosure.kt
Roman Artemev efec82c0eb Update test data
* add new tests for coroutines
 * add copy of some tests without dependency on stdlib
2018-08-08 18:33:41 +03:00

36 lines
690 B
Kotlin
Vendored

// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
// WITH_COROUTINES
// COMMON_COROUTINES_TEST
import helpers.*
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
var result = 0
class Controller {
suspend fun suspendHere(): String = suspendCoroutineUninterceptedOrReturn { x ->
result++
x.resume("OK")
COROUTINE_SUSPENDED
}
}
fun builder(c: suspend Controller.() -> Unit) {
c.startCoroutine(Controller(), EmptyContinuation)
}
fun box(): String {
for (i in 1..3) {
builder {
if (suspendHere() != "OK") throw RuntimeException("fail 1")
}
}
if (result != 3) return "fail 2: $result"
return "OK"
}