Fix inlining of tail call suspend function

When inlining tail-call suspend function to regular
suspend function in JS BE, don't forget to insert suspension point.
See KT-16951
This commit is contained in:
Alexey Andreev
2017-03-20 18:34:08 +03:00
parent 466540399c
commit 6ba3812582
9 changed files with 134 additions and 14 deletions
@@ -0,0 +1,53 @@
// IGNORE_BACKEND: NATIVE
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.experimental.*
fun box(): String {
async {
val a = foo(23)
log(a)
val b = foo(42)
log(b)
}
while (!finished) {
log("--")
proceed()
}
if (result != "suspend:23;--;23;suspend:42;--;42;--;done;") return "fail: $result"
return "OK"
}
var result = ""
fun log(message: Any) {
result += "$message;"
}
var proceed: () -> Unit = { }
var finished = false
suspend fun bar(x: Int): Int = suspendCoroutine { c ->
log("suspend:$x")
proceed = { c.resume(x) }
}
inline suspend fun foo(x: Int) = bar(x)
fun async(a: suspend () -> Unit) {
a.startCoroutine(object : Continuation<Unit> {
override fun resume(value: Unit) {
proceed = {
log("done")
finished = true
}
}
override fun resumeWithException(e: Throwable) {
}
override val context = EmptyCoroutineContext
})
}