JS: fix translation of safe calls to suspend unit functions
See KT-21317
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
import helpers.*
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
var log = ""
|
||||
var postponed: () -> Unit = { }
|
||||
var complete = false
|
||||
|
||||
suspend fun suspendHere(x: String): Unit {
|
||||
log += "suspendHere($x);"
|
||||
return suspendCoroutineOrReturn { c ->
|
||||
postponed = { c.resume(Unit) }
|
||||
log += "suspended;"
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
}
|
||||
|
||||
class A(val x: String) {
|
||||
suspend fun foo() = suspendHere("A.foo($x)")
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(handleResultContinuation {
|
||||
log += "complete;"
|
||||
complete = true
|
||||
})
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a1: A? = A("*")
|
||||
val a2: A? = null
|
||||
builder {
|
||||
val r1 = a1?.foo().simpleName + ";"
|
||||
log += r1
|
||||
val r2 = a2?.foo().simpleName + ";"
|
||||
log += r2
|
||||
A("@").foo()
|
||||
}
|
||||
|
||||
while (!complete) {
|
||||
log += "resuming;"
|
||||
postponed()
|
||||
}
|
||||
|
||||
if (log != "suspendHere(A.foo(*));suspended;resuming;Unit;null;suspendHere(A.foo(@));suspended;resuming;complete;") return "fail: $log"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
val Any?.simpleName: String
|
||||
get() = if (this == null) "null" else "Unit"
|
||||
Reference in New Issue
Block a user