Files
kotlin-fork/compiler/testData/codegen/box/ranges/kt37370.kt
T
Dmitry Petrov 6809f4439c Fix range-based 'for' loop with 'continue' in range bounds
1. Search for increment function in range element type, not in inferred
induction variable type
(which can be inappropriate, e.g., 'Nothing' in case of 'continue').

2. Handle nested loops with shared exit labels
(generated by JVM_IR for KT-37370 case).

KT-37370 KT-37373
2020-03-17 12:18:48 +03:00

65 lines
1.2 KiB
Kotlin
Vendored

// WITH_RUNTIME
fun testContinue1() {
for (i in 0..1) {
for (j in continue downTo 1) {}
}
}
fun testContinue2() {
for (i in 0..1) {
for (j in 1 downTo continue) {}
}
}
fun falseCond() = false
fun testContinue3() {
for (i in 0..1) {
for (j in (if (falseCond()) 10 else continue) downTo 1) {}
}
}
fun testContinue4() {
for (i in 0..1) {
for (j in 10 downTo (if (falseCond()) 1 else continue)) {}
}
}
fun testContinue5() {
for (i in 0..1) {
for (j in (
if (try {
if (falseCond()) true else return
} finally {
if (!falseCond()) continue
}
)
10
else
continue
)
downTo 1) {
//...
}
}
}
fun start(i1: Int, i2: Int, i3: Int) = 10
fun testContinue6() {
for (i in 0..1) {
for (j in start(1, 2, continue) downTo 0) {
}
}
}
fun box(): String {
testContinue1()
testContinue2()
testContinue3()
testContinue4()
testContinue5()
testContinue6()
return "OK"
}