Files
kotlin-fork/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/breakInLoopConditions.kt
T
Mads Ager 8588412a56 [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
2021-03-12 13:46:27 +01:00

40 lines
813 B
Kotlin
Vendored

// 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()
}