Files
kotlin/compiler/testData/codegen/box/coroutines/inlineSuspendFunction.kt
Denis Zharkov d92c403f9e Move helpers for coroutine tests in separate package
It will help to skip their content when rendering bytecode listing
for box tests
2017-05-05 14:01:50 +03:00

48 lines
1.2 KiB
Kotlin
Vendored

// IGNORE_BACKEND: NATIVE
// WITH_RUNTIME
// WITH_COROUTINES
import helpers.*
// WITH_REFLECT
// CHECK_NOT_CALLED: suspendInline_61zpoe$
// CHECK_NOT_CALLED: suspendInline_6r51u9$
// CHECK_NOT_CALLED: suspendInline
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
class Controller {
fun withValue(v: String, x: Continuation<String>) {
x.resume(v)
}
suspend inline fun suspendInline(v: String): String = suspendCoroutineOrReturn { x ->
withValue(v, x)
COROUTINE_SUSPENDED
}
suspend inline fun suspendInline(crossinline b: () -> String): String = suspendInline(b())
suspend inline fun <reified T : Any> suspendInline(): String = suspendInline({ T::class.simpleName!! })
}
fun builder(c: suspend Controller.() -> Unit) {
c.startCoroutine(Controller(), EmptyContinuation)
}
class OK
fun box(): String {
var result = ""
builder {
result = suspendInline("56")
if (result != "56") throw RuntimeException("fail 1")
result = suspendInline { "57" }
if (result != "57") throw RuntimeException("fail 2")
result = suspendInline<OK>()
}
return result
}