mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 08:31:26 +00:00
48 lines
1.2 KiB
Kotlin
Vendored
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
|
|
}
|