[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:
Mads Ager
2021-03-05 12:30:12 +01:00
committed by max-kammerer
parent d0d3b57366
commit 8588412a56
10 changed files with 85 additions and 3 deletions
@@ -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()
}