Imitate support for suspend modifier on parameterless lambdas

#KT-22766 In Progress
This commit is contained in:
Denis Zharkov
2018-01-24 18:29:38 +03:00
parent 5c81d9fd6b
commit ef01f641f3
10 changed files with 99 additions and 0 deletions
@@ -0,0 +1,31 @@
// WITH_RUNTIME
// WITH_COROUTINES
import helpers.*
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
suspend fun suspendHere(v: String): String = suspendCoroutineOrReturn { x ->
x.resume(v)
COROUTINE_SUSPENDED
}
suspend fun foo(): String {
var a = "OK"
var i = 0
val x = suspend {
suspendHere(a[i++].toString())
}
return x() + x.invoke()
}
fun box(): String {
var result = ""
suspend {
result = foo()
}.startCoroutine(EmptyContinuation)
return result
}