Files
kotlin-fork/compiler/testData/codegen/box/arrays/forInReversed/reversedArrayOriginalUpdatedInLoopBody.kt
T
Mark Punzalan 1b703448d3 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.
2019-04-11 08:54:55 +02:00

18 lines
463 B
Kotlin
Vendored

// 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"
}