Support common calls on suspend function typed values
Also support multiple value parameters in suspend function type #KT-15379 Fixed #KT-15380 Fixed
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// IGNORE_BACKEND: JS
|
||||
import kotlin.coroutines.*
|
||||
|
||||
suspend fun suspendHere(v: String): String = CoroutineIntrinsics.suspendCoroutineOrReturn { x ->
|
||||
x.resume(v)
|
||||
CoroutineIntrinsics.SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
suspend fun foo(c: suspend Double.(Long, Int, String) -> String) = (1.0).c(56L, 55, "abc")
|
||||
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
var final = ""
|
||||
|
||||
builder {
|
||||
final = foo { l, i, s ->
|
||||
result = suspendHere("$this#$l#$i#$s")
|
||||
"OK"
|
||||
}
|
||||
}
|
||||
|
||||
if (result != "1.0#56#55#abc") return "fail: $result"
|
||||
|
||||
return final
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// IGNORE_BACKEND: JS
|
||||
import kotlin.coroutines.*
|
||||
|
||||
suspend fun suspendHere(v: String): String = CoroutineIntrinsics.suspendCoroutineOrReturn { x ->
|
||||
x.resume(v)
|
||||
CoroutineIntrinsics.SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
suspend fun foo1(c: suspend () -> Unit) = c()
|
||||
suspend fun foo2(c: suspend String.() -> Int) = "2".c()
|
||||
suspend fun foo3(c: suspend (String) -> Int) = c("3")
|
||||
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
|
||||
builder {
|
||||
foo1 {
|
||||
result = suspendHere("begin#")
|
||||
}
|
||||
|
||||
val q2 = foo2 { result += suspendHere(this) + "#"; 1 }
|
||||
val q3 = foo3 { result += suspendHere(it); 2 }
|
||||
|
||||
if (q2 != 1) throw RuntimeException("fail q2")
|
||||
if (q3 != 2) throw RuntimeException("fail q3")
|
||||
}
|
||||
|
||||
if (result != "begin#2#3") return "fail: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user