Handle reversed() in ForLoopsLowering.
We get the info for the underlying progression and invert it. For progressions whose last bound was open (e.g., `until` loop), the reversed version will have an open first bound and so the induction variable must be incremented first. Also unified the way of extracting HeaderInfo out of changed calls (e.g., `indices.reversed()`), and fixed declaration parents in ForLoopsLowering.
This commit is contained in:
committed by
max-kammerer
parent
3d1b6fb83c
commit
1b703448d3
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
// WITH_RUNTIME
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
val arr = intArrayOf(1, 2, 3, 4)
|
||||
var sum = 0
|
||||
var index = 0
|
||||
for (i in arr.reversedArray()) {
|
||||
// reversedArray() returns a new Array with elements in reversed order.
|
||||
// Modifying the original array should have no effect on the iteration subject.
|
||||
arr[index++] = 0
|
||||
sum = sum * 10 + i
|
||||
}
|
||||
assertEquals(4321, sum)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user