JS: coroutines: fixes after code review
This commit is contained in:
@@ -38,13 +38,14 @@ fun box(): String {
|
||||
}
|
||||
result += "ignore"
|
||||
}
|
||||
result += "*"
|
||||
}
|
||||
finally {
|
||||
result += "finally"
|
||||
}
|
||||
result += "."
|
||||
}
|
||||
if (value != "AC!ED!@finally.") return "fail: $value"
|
||||
if (value != "AC!ED!@*finally.") return "fail: $value"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Controller {
|
||||
var result = ""
|
||||
|
||||
suspend fun <T> suspendWithResult(value: T, c: Continuation<T>) {
|
||||
c.resume(value)
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>): String {
|
||||
val controller = Controller()
|
||||
c(controller).resume(Unit)
|
||||
return controller.result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val value = builder {
|
||||
for (x in listOf("O", "$", "K")) {
|
||||
if (x == "$") continue
|
||||
result += suspendWithResult(x)
|
||||
}
|
||||
result += "."
|
||||
}
|
||||
if (value != "OK.") return "fail: suspend in for body: $value"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
// TODO: fix bug in JVM backend and remove this directive
|
||||
// TARGET_BACKEND: JS
|
||||
|
||||
class Controller {
|
||||
var result = ""
|
||||
|
||||
suspend fun <T> suspendWithResult(value: T, c: Continuation<T>) {
|
||||
result += "["
|
||||
c.resume(value)
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>): String {
|
||||
val controller = Controller()
|
||||
c(controller).resume(Unit)
|
||||
return controller.result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var value = builder {
|
||||
for (v in listOf("A", "B", "C")) {
|
||||
when (v) {
|
||||
"A" -> result += "A;"
|
||||
"B" -> result += suspendWithResult(v) + "]"
|
||||
else -> result += suspendWithResult(v) + "]!"
|
||||
}
|
||||
}
|
||||
}
|
||||
if (value != "A;[B][C]!") return "fail: suspend as if condition: $value"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -4744,6 +4744,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forContinue.kt")
|
||||
public void testForContinue() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/controlFlow/forContinue.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forStatement.kt")
|
||||
public void testForStatement() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/controlFlow/forStatement.kt");
|
||||
|
||||
@@ -4744,6 +4744,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forContinue.kt")
|
||||
public void testForContinue() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/controlFlow/forContinue.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forStatement.kt")
|
||||
public void testForStatement() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/controlFlow/forStatement.kt");
|
||||
|
||||
Reference in New Issue
Block a user