JVM_IR: Support interface delegation of suspend functions

The issue was, that built IR function does not have a PSI element,
which is required to report error on suspend functions inside monitors.
In this case, use PSI element of the class, containing the function,
which is consistent with old BE.
This commit is contained in:
Ilmir Usmanov
2020-01-21 13:47:58 +01:00
parent e34a207725
commit a55989a2a5
6 changed files with 81 additions and 5 deletions
@@ -0,0 +1,56 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FULL_JDK
// WITH_RUNTIME
// WITH_COROUTINES
// CHECK_TAIL_CALL_OPTIMIZATION
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
suspend fun suspendThere(v: String): String = suspendCoroutineUninterceptedOrReturn { x ->
TailCallOptimizationChecker.saveStackTrace(x)
x.resume(v)
COROUTINE_SUSPENDED
}
interface I {
suspend fun suspendHere(): String
suspend fun suspendHereNoTailCall(): String
}
class A : I {
override suspend fun suspendHere(): String = suspendThere("OK")
override suspend fun suspendHereNoTailCall(): String {
suspendThere("FAIL 2")
return "OK"
}
}
open class B(val x: I) : I by x // open override suspend fun suspendHere() = x.suspendHere()
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = ""
builder {
result = B(A()).suspendHere()
}
TailCallOptimizationChecker.checkNoStateMachineIn("suspendHere")
TailCallOptimizationChecker.checkNoStateMachineIn("suspendHere\$suspendImpl")
if (result != "OK") return "FAIL 1"
builder {
result = B(A()).suspendHereNoTailCall()
}
TailCallOptimizationChecker.checkStateMachineIn("suspendHereNoTailCall")
TailCallOptimizationChecker.checkNoStateMachineIn("suspendHereNoTailCall\$suspendImpl")
return result
}