KT-12275 Preserve evaluation order when do..while loop with extractable condition contains continue statement
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
package foo
|
||||
|
||||
private inline fun bar(predicate: (Char) -> Boolean): Int {
|
||||
var i = -1
|
||||
val str = "abc "
|
||||
do {
|
||||
i++
|
||||
if (i == 1) continue
|
||||
log(i.toString())
|
||||
} while (predicate(str[i]) && i < 3)
|
||||
return i
|
||||
}
|
||||
|
||||
private fun test(c: Char): Int {
|
||||
return bar {
|
||||
log(it.toString())
|
||||
it != c
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(0, test('a'))
|
||||
assertEquals("0;a;", pullLog())
|
||||
|
||||
assertEquals(1, test('b'))
|
||||
assertEquals("0;a;b;", pullLog())
|
||||
|
||||
assertEquals(2, test('c'))
|
||||
assertEquals("0;a;b;2;c;", pullLog())
|
||||
|
||||
assertEquals(3, test('*'))
|
||||
assertEquals("0;a;b;2;c;3; ;", pullLog())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package foo
|
||||
|
||||
private inline fun bar(predicate: (Int) -> Boolean) {
|
||||
var i = -1
|
||||
outer@do {
|
||||
i++
|
||||
if (i == 1) continue
|
||||
var j = -1
|
||||
do {
|
||||
++j
|
||||
if (j == 1) {
|
||||
if (i == 3) continue@outer else continue
|
||||
}
|
||||
log("i$j")
|
||||
} while (j < 3)
|
||||
log("o$i")
|
||||
} while (predicate(i))
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
bar {
|
||||
log("p$it")
|
||||
it < 5
|
||||
}
|
||||
assertEquals("i0;i2;i3;o0;p0;p1;i0;i2;i3;o2;p2;i0;p3;i0;i2;i3;o4;p4;i0;i2;i3;o5;p5;", pullLog())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user