Files
kotlin-fork/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakOrContinueInLoopCondition.fir.kt
T
Jinseong Jeon b4a5eec5f4 Raw FIR: correct loop target for break/continue in do-while loop condition
As shown in KT-44412 (or KT-45319 or KT-17728):
```
fun test5() {
    var i = 0
    Outer@while (true) {
        ++i
        var j = 0
        Inner@do {
            ++j
        } while (if (j >= 3) false else break) // break@Inner
        if (i == 3) break
    }
}
```

To properly set the loop target for `break` in do-while loop condition,
the loop target for that do-while loop should be ready before parsing
the loop condition.

Previously, Raw FIR loop building configures loop target after visiting
loop conditions. This commit splits the configuration and lets the
builders prepare the loop target for do-while loop only.
2021-04-01 20:07:50 +03:00

35 lines
807 B
Kotlin
Vendored

fun test() {
l@ for (i in if (true) 1..10 else <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue@l<!>) {}
for (i in if (true) 1..10 else <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>) {}
while (<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break<!>) {}
l@ while (<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break@l<!>) {}
do {} while (continue)
l@ do {} while (continue@l)
//KT-5704
var i = 0
while (if(i++ == 10) <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break<!> else <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>) {}
}
fun test2(b: Boolean) {
while (b) {
while (break) {}
}
do {
while (continue) {}
} while (b)
while (b) {
do {} while (break)
}
for (i in 1..10) {
for (j in if (true) 1..10 else continue) {
}
}
}