JS: fix noInline version of inline suspend fun (KT-27611 fixed)

This commit is contained in:
Anton Bannykh
2018-10-19 14:56:55 +03:00
parent 455db32199
commit 829bdf6061
11 changed files with 145 additions and 66 deletions
@@ -0,0 +1,61 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1280
// MODULE: lib
// FILE: lib.kt
import kotlin.coroutines.*
var resume: () -> Unit = {}
suspend fun suspendAndReturn(msg: String): String {
return suspendCoroutine<String> { cont ->
resume = {
cont.resume(msg)
}
}
}
suspend fun <T> runSus(block: suspend () -> T): T = block()
abstract class A {
fun f() = o()
abstract fun o(): String
}
// MODULE: libInline(lib)
// FILE: libInline.kt
suspend inline fun foo(): String {
val a = object : A() {
override fun o(): String = "O"
}
val k = "K"
return suspendAndReturn(a.f()) + runSus {
val b = object : A() {
override fun o(): String = k
}
runSus { suspendAndReturn(b.f()) }
}
}
// MODULE: main(libInline, lib)
// FILE: main.kt
import kotlin.coroutines.*
fun box(): String {
var testResult: String = "fail"
val continuation = Continuation<String>(EmptyCoroutineContext) { result ->
testResult = result.getOrThrow()
}
// Test the noinline version of public inline suspend functions
js("libInline").foo(continuation)
resume()
resume()
return testResult
}
+1 -1
View File
@@ -14,4 +14,4 @@ suspend fun bar(): Unit {
println(a + b)
}
// LINES: 39 39 4 4 4 5 5 44 44 5 88 44 5 5 6 4 4 4 15 9 9 9 9 15 9 9 9 * 15 10 10 11 11 11 2 11 11 * 11 12 12 13 13 13 2 13 13 13 13 14 14
// LINES: 39 39 4 4 4 5 5 44 44 5 88 44 5 5 6 4 4 4 15 9 9 9 * 15 10 10 11 11 11 2 11 11 * 11 12 12 13 13 13 2 13 13 13 13 14 14 * 15 9 9 9 9
@@ -8,4 +8,4 @@ suspend fun foo() {
suspend fun delay() {
}
// LINES: 6 1 1 1 1 6 1 1 * 6 2 2 2 2 2 * 3 3 4 4 4 2 4 4 5 5 * 9
// LINES: 6 1 1 * 6 2 2 2 2 2 * 3 3 4 4 4 2 4 4 5 5 * 6 1 1 1 1 9