[JS] Invoke processing separately for suspend and non-suspend function

^KT-62771 fixed
This commit is contained in:
Ilya Goncharov
2023-10-25 13:28:58 +00:00
committed by Space Team
parent f227447837
commit 573bc34b56
6 changed files with 125 additions and 10 deletions
@@ -956,6 +956,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest {
runTest("js/js.translator/testData/box/coroutines/suspendFunctionalInterface.kt");
}
@Test
@TestMetadata("suspendInvokeWithSuspendKlassRef.kt")
public void testSuspendInvokeWithSuspendKlassRef() throws Exception {
runTest("js/js.translator/testData/box/coroutines/suspendInvokeWithSuspendKlassRef.kt");
}
@Test
@TestMetadata("suspendMethodWithSuperCall.kt")
public void testSuspendMethodWithSuperCall() throws Exception {
@@ -956,6 +956,12 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest {
runTest("js/js.translator/testData/box/coroutines/suspendFunctionalInterface.kt");
}
@Test
@TestMetadata("suspendInvokeWithSuspendKlassRef.kt")
public void testSuspendInvokeWithSuspendKlassRef() throws Exception {
runTest("js/js.translator/testData/box/coroutines/suspendInvokeWithSuspendKlassRef.kt");
}
@Test
@TestMetadata("suspendMethodWithSuperCall.kt")
public void testSuspendMethodWithSuperCall() throws Exception {
@@ -956,6 +956,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
runTest("js/js.translator/testData/box/coroutines/suspendFunctionalInterface.kt");
}
@Test
@TestMetadata("suspendInvokeWithSuspendKlassRef.kt")
public void testSuspendInvokeWithSuspendKlassRef() throws Exception {
runTest("js/js.translator/testData/box/coroutines/suspendInvokeWithSuspendKlassRef.kt");
}
@Test
@TestMetadata("suspendMethodWithSuperCall.kt")
public void testSuspendMethodWithSuperCall() throws Exception {
@@ -956,6 +956,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
runTest("js/js.translator/testData/box/coroutines/suspendFunctionalInterface.kt");
}
@Test
@TestMetadata("suspendInvokeWithSuspendKlassRef.kt")
public void testSuspendInvokeWithSuspendKlassRef() throws Exception {
runTest("js/js.translator/testData/box/coroutines/suspendInvokeWithSuspendKlassRef.kt");
}
@Test
@TestMetadata("suspendMethodWithSuperCall.kt")
public void testSuspendMethodWithSuperCall() throws Exception {
@@ -0,0 +1,85 @@
// TARGET_BACKEND: JS_IR
// ONLY_IR_DCE
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
private var stopped = false
fun build(c: suspend () -> Unit) {
c.startCoroutine(object : Continuation<Unit> {
override fun resumeWith(x: Result<Unit>) {
stopped = true
}
override val context = EmptyCoroutineContext
})
}
inline fun <reified T : Any> klassToString() = T::class.toString()
typealias SusFun0 = suspend () -> Unit
typealias SusFun1 = suspend (String) -> Unit
typealias SusFun2 = suspend (String, String) -> Unit
val SusFun0Prop = klassToString<SusFun0>()
val SusFun1Prop = klassToString<SusFun1>()
val SusFun2Prop = klassToString<SusFun2>()
class Foo {
suspend fun susFun0(
parse: suspend () -> String
): String {
return "0" + parse()
}
suspend fun susFun1(
parse: suspend (String) -> String
): String {
return "1" + parse("a")
}
suspend fun susFun2(
parse: suspend (String, String) -> String
): String {
return "2" + parse("a", "b")
}
}
fun box(): String {
SusFun0Prop
SusFun1Prop
SusFun2Prop
var log = ""
val foo = Foo()
build {
val foo0 = foo.susFun0 {
"0"
}
log += foo0
val foo1 = foo.susFun1 { one ->
one + "1"
}
log += foo1
val foo2 = foo.susFun2 { one, two ->
one + two + "2"
}
log += foo2
}
while (!stopped) {
}
if (log != "001a12ab2") return "fail: $log"
return "OK"
}