Fix fallthrough in suspendable switch [#KT-22694, #KT-23687]
* do not explicitly put break for each case * add test for related cases
This commit is contained in:
committed by
Roman Artemev
parent
0c6256d003
commit
5241b37ad9
@@ -0,0 +1,49 @@
|
|||||||
|
// IGNORE_BACKEND: JS_IR
|
||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// WITH_COROUTINES
|
||||||
|
// COMMON_COROUTINES_TEST
|
||||||
|
import helpers.*
|
||||||
|
import COROUTINES_PACKAGE.*
|
||||||
|
import COROUTINES_PACKAGE.intrinsics.*
|
||||||
|
|
||||||
|
enum class Foo(vararg expected: String) {
|
||||||
|
A("start", "A", "end"),
|
||||||
|
B("start", "BCD", "end"),
|
||||||
|
C("start", "BCD", "end"),
|
||||||
|
D("start", "BCD", "end"),
|
||||||
|
E("start", "E", "end"),
|
||||||
|
F("start", "end");
|
||||||
|
|
||||||
|
val expected = expected.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
for (c in Foo.values()) {
|
||||||
|
val actual = getSequence(c).toList()
|
||||||
|
if (actual != c.expected) {
|
||||||
|
return "FAIL: -- ${c.expected} != $actual"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getSequence(a: Foo) =
|
||||||
|
buildSequence {
|
||||||
|
yield("start")
|
||||||
|
when (a) {
|
||||||
|
Foo.A -> {
|
||||||
|
yield("A")
|
||||||
|
}
|
||||||
|
Foo.B,
|
||||||
|
Foo.C,
|
||||||
|
Foo.D-> {
|
||||||
|
yield("BCD")
|
||||||
|
}
|
||||||
|
Foo.E-> {
|
||||||
|
yield("E")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yield("end")
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
// IGNORE_BACKEND: JS_IR
|
||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// WITH_COROUTINES
|
||||||
|
// COMMON_COROUTINES_TEST
|
||||||
|
import helpers.*
|
||||||
|
import COROUTINES_PACKAGE.*
|
||||||
|
import COROUTINES_PACKAGE.intrinsics.*
|
||||||
|
|
||||||
|
var result = ""
|
||||||
|
|
||||||
|
fun id(s: String) { result += s }
|
||||||
|
|
||||||
|
suspend fun bar() = Unit
|
||||||
|
|
||||||
|
suspend fun foo(a: Int) {
|
||||||
|
when (a) {
|
||||||
|
0 -> {
|
||||||
|
id("0")
|
||||||
|
bar() // slice switch
|
||||||
|
}
|
||||||
|
1, 2 -> {
|
||||||
|
id("$a")
|
||||||
|
}
|
||||||
|
else -> Unit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun builder(callback: suspend () -> Unit) {
|
||||||
|
callback.startCoroutine(object : ContinuationAdapter<Unit>() {
|
||||||
|
override val context: CoroutineContext = EmptyCoroutineContext
|
||||||
|
override fun resume(value: Unit) = Unit
|
||||||
|
override fun resumeWithException(exception: Throwable) {
|
||||||
|
id("FAIL WITH EXCEPTION: ${exception.message}")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box():String {
|
||||||
|
id("a")
|
||||||
|
builder {
|
||||||
|
foo(0)
|
||||||
|
foo(1)
|
||||||
|
foo(2)
|
||||||
|
}
|
||||||
|
id("b")
|
||||||
|
if (result != "a012b") return "FAIL: $result"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Generated
+20
@@ -6130,6 +6130,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/ifStatement.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/ifStatement.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22694.kt")
|
||||||
|
public void testKt22694_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/kt22694.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22694.kt")
|
||||||
|
public void testKt22694_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/kt22694.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("labeledWhile.kt")
|
@TestMetadata("labeledWhile.kt")
|
||||||
public void testLabeledWhile_1_2() throws Exception {
|
public void testLabeledWhile_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/labeledWhile.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/labeledWhile.kt", "kotlin.coroutines.experimental");
|
||||||
@@ -6180,6 +6190,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/throwInTryWithHandleResult.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/throwInTryWithHandleResult.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenWithSuspensions.kt")
|
||||||
|
public void testWhenWithSuspensions_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whenWithSuspensions.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenWithSuspensions.kt")
|
||||||
|
public void testWhenWithSuspensions_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whenWithSuspensions.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("whileStatement.kt")
|
@TestMetadata("whileStatement.kt")
|
||||||
public void testWhileStatement_1_2() throws Exception {
|
public void testWhileStatement_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whileStatement.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whileStatement.kt", "kotlin.coroutines.experimental");
|
||||||
|
|||||||
+20
@@ -6130,6 +6130,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/ifStatement.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/ifStatement.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22694.kt")
|
||||||
|
public void testKt22694_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/kt22694.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22694.kt")
|
||||||
|
public void testKt22694_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/kt22694.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("labeledWhile.kt")
|
@TestMetadata("labeledWhile.kt")
|
||||||
public void testLabeledWhile_1_2() throws Exception {
|
public void testLabeledWhile_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/labeledWhile.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/labeledWhile.kt", "kotlin.coroutines.experimental");
|
||||||
@@ -6180,6 +6190,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/throwInTryWithHandleResult.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/throwInTryWithHandleResult.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenWithSuspensions.kt")
|
||||||
|
public void testWhenWithSuspensions_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whenWithSuspensions.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenWithSuspensions.kt")
|
||||||
|
public void testWhenWithSuspensions_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whenWithSuspensions.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("whileStatement.kt")
|
@TestMetadata("whileStatement.kt")
|
||||||
public void testWhileStatement_1_2() throws Exception {
|
public void testWhileStatement_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whileStatement.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whileStatement.kt", "kotlin.coroutines.experimental");
|
||||||
|
|||||||
+20
@@ -6130,6 +6130,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/ifStatement.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/ifStatement.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22694.kt")
|
||||||
|
public void testKt22694_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/kt22694.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22694.kt")
|
||||||
|
public void testKt22694_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/kt22694.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("labeledWhile.kt")
|
@TestMetadata("labeledWhile.kt")
|
||||||
public void testLabeledWhile_1_2() throws Exception {
|
public void testLabeledWhile_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/labeledWhile.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/labeledWhile.kt", "kotlin.coroutines.experimental");
|
||||||
@@ -6180,6 +6190,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/throwInTryWithHandleResult.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/throwInTryWithHandleResult.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenWithSuspensions.kt")
|
||||||
|
public void testWhenWithSuspensions_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whenWithSuspensions.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenWithSuspensions.kt")
|
||||||
|
public void testWhenWithSuspensions_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whenWithSuspensions.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("whileStatement.kt")
|
@TestMetadata("whileStatement.kt")
|
||||||
public void testWhileStatement_1_2() throws Exception {
|
public void testWhileStatement_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whileStatement.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whileStatement.kt", "kotlin.coroutines.experimental");
|
||||||
|
|||||||
@@ -98,8 +98,6 @@ class CoroutineBodyTransformer(private val context: CoroutineTransformationConte
|
|||||||
currentBlock = caseBlock
|
currentBlock = caseBlock
|
||||||
|
|
||||||
jsCase.statements.forEach { accept(it) }
|
jsCase.statements.forEach { accept(it) }
|
||||||
currentBlock.statements += stateAndJump(jointBlock, x)
|
|
||||||
|
|
||||||
jsCase.statements.clear()
|
jsCase.statements.clear()
|
||||||
jsCase.statements += caseBlock.statements
|
jsCase.statements += caseBlock.statements
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -5410,6 +5410,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/ifStatement.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/ifStatement.kt", "kotlin.coroutines.experimental");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22694.kt")
|
||||||
|
public void testKt22694_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/kt22694.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("labeledWhile.kt")
|
@TestMetadata("labeledWhile.kt")
|
||||||
public void testLabeledWhile_1_2() throws Exception {
|
public void testLabeledWhile_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/labeledWhile.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/labeledWhile.kt", "kotlin.coroutines.experimental");
|
||||||
@@ -5435,6 +5440,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/throwInTryWithHandleResult.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/throwInTryWithHandleResult.kt", "kotlin.coroutines.experimental");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenWithSuspensions.kt")
|
||||||
|
public void testWhenWithSuspensions_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whenWithSuspensions.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("whileStatement.kt")
|
@TestMetadata("whileStatement.kt")
|
||||||
public void testWhileStatement_1_2() throws Exception {
|
public void testWhileStatement_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whileStatement.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whileStatement.kt", "kotlin.coroutines.experimental");
|
||||||
|
|||||||
+20
@@ -5855,6 +5855,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/ifStatement.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/ifStatement.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22694.kt")
|
||||||
|
public void testKt22694_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/kt22694.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22694.kt")
|
||||||
|
public void testKt22694_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/kt22694.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("labeledWhile.kt")
|
@TestMetadata("labeledWhile.kt")
|
||||||
public void testLabeledWhile_1_2() throws Exception {
|
public void testLabeledWhile_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/labeledWhile.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/labeledWhile.kt", "kotlin.coroutines.experimental");
|
||||||
@@ -5905,6 +5915,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/throwInTryWithHandleResult.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/throwInTryWithHandleResult.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenWithSuspensions.kt")
|
||||||
|
public void testWhenWithSuspensions_1_2() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whenWithSuspensions.kt", "kotlin.coroutines.experimental");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenWithSuspensions.kt")
|
||||||
|
public void testWhenWithSuspensions_1_3() throws Exception {
|
||||||
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whenWithSuspensions.kt", "kotlin.coroutines");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("whileStatement.kt")
|
@TestMetadata("whileStatement.kt")
|
||||||
public void testWhileStatement_1_2() throws Exception {
|
public void testWhileStatement_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whileStatement.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/controlFlow/whileStatement.kt", "kotlin.coroutines.experimental");
|
||||||
|
|||||||
Reference in New Issue
Block a user