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:
Roman Artemev
2018-07-23 14:57:14 +03:00
committed by Roman Artemev
parent 0c6256d003
commit 5241b37ad9
8 changed files with 188 additions and 2 deletions
@@ -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"
}