[JVM IR] Support break in do-while condition.
This breaks from the loop itself which is inconsistent with what happens for breaks in while conditions. Also, the frontend will report that code after the loop is unreachable, which it isn't. :-\ However, those issues are covered in https://youtrack.jetbrains.com/issue/KT-17728, so for now we follow the old backend to not "break" anyone. :) Fixes KT-44412
This commit is contained in:
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
// See: https://youtrack.jetbrains.com/issue/KT-45319
|
||||
// IGNORE_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
fun breakInDoWhileCondition(): String {
|
||||
var i = 0
|
||||
while (true) {
|
||||
++i
|
||||
var j = 0
|
||||
do {
|
||||
++j
|
||||
} while (break)
|
||||
if (j != 1) return "FAIL1"
|
||||
if (i == 3) break
|
||||
}
|
||||
if (i != 3) return "FAIL2"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun breakInWhileCondition(): String {
|
||||
var i = 0
|
||||
while (true) {
|
||||
++i
|
||||
var j = 0
|
||||
while (break) {
|
||||
j++
|
||||
}
|
||||
return "FAIL3"
|
||||
}
|
||||
if (i != 1) return "FAIL4"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val breakInDoWhileResult = breakInDoWhileCondition()
|
||||
if (breakInDoWhileResult != "OK") return breakInDoWhileResult
|
||||
return breakInWhileCondition()
|
||||
}
|
||||
Reference in New Issue
Block a user