Imitate support for suspend modifier on parameterless lambdas
#KT-22766 In Progress
This commit is contained in:
+31
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import kotlin.coroutines.experimental.Continuation
|
||||
import kotlin.coroutines.experimental.CoroutineContext
|
||||
import kotlin.coroutines.experimental.startCoroutine
|
||||
|
||||
fun bar() {
|
||||
suspend {
|
||||
println()
|
||||
}.startCoroutine(object: Continuation<Unit> {
|
||||
override val context: CoroutineContext
|
||||
get() = TODO("not implemented")
|
||||
|
||||
override fun resume(value: Unit) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun resumeWithException(exception: Throwable) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun bar(): kotlin.Unit
|
||||
Reference in New Issue
Block a user