Check for COROUTINE_SUSPENDED inside callable reference

#KT-41429 Fixed
This commit is contained in:
Ilmir Usmanov
2020-09-01 21:34:31 +02:00
parent 4303e8126f
commit 1c97eafea8
17 changed files with 98 additions and 14 deletions
@@ -0,0 +1,30 @@
// IGNORE_BACKEND: JS_IR
// IGNORE_BACKEND: JS_IR_ES6
// WITH_RUNTIME
// WITH_COROUTINES
import helpers.*
import kotlin.coroutines.*
inline class R(val x: Any)
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
suspend fun <T> call(fn: suspend () -> T) = fn()
fun useR(r: R) = if (r.x == "OK") "OK" else "fail: $r"
var c: Continuation<R>? = null
suspend fun ok() = suspendCoroutine<R> { c = it }
fun box(): String {
var res: String = "fail"
builder {
res = useR(call(::ok))
}
c?.resume(R("OK"))
return res
}
@@ -1,5 +1,6 @@
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JVM_IR
import helpers.*
import kotlin.coroutines.*
@@ -23,4 +23,5 @@ suspend fun test() {
// -- 1 in 'useICAny(suspendGeneric(ICAny("")))
// -- 1 in 'equals-impl' for ICAny
// 2 INVOKEVIRTUAL ICAny\.unbox-impl
// -- 2 on resume path of suspendICAny
// 4 INVOKEVIRTUAL ICAny\.unbox-impl
@@ -11,14 +11,14 @@ fun useIC(x: IC1) {}
fun useAny(x: Any) {}
suspend fun test() {
useIC(suspendIC())
useIC(suspendIC()) // IC1.unbox-impl of resume path
useIC(suspendGeneric(IC1(IC0("")))) // IC1.box-impl, IC1.unbox-impl
useAny(suspendAny())
useAny(suspendIC()) // IC1.box-impl
useAny(suspendIC()) // IC1.box-impl, IC1.unbox-impl of resume path
}
// 0 INVOKESTATIC IC0\.box-impl
// 3 INVOKESTATIC IC1\.box-impl
// 1 INVOKEVIRTUAL IC0\.unbox-impl
// 2 INVOKEVIRTUAL IC1\.unbox-impl
// 4 INVOKEVIRTUAL IC1\.unbox-impl
@@ -23,4 +23,5 @@ suspend fun test() {
// -- 1 in 'useICString(suspendGeneric(ICString("")))
// -- 1 in 'equals-impl' for ICString
// 2 INVOKEVIRTUAL ICString\.unbox-impl
// -- 2 in resume path of suspendICString
// 4 INVOKEVIRTUAL ICString\.unbox-impl
@@ -7,5 +7,5 @@ inline class OurAny(val a: Any)
suspend fun returnsUnboxed(): OurAny = OurAny("OK")
// 1 INVOKESTATIC kotlin/Result.box-impl
// 0 INVOKESTATIC kotlin/Result.box-impl
// 0 INVOKESTATIC OurAny.box-impl