Files
kotlin-fork/compiler/testData/codegen/box/ranges/forInArrayWithArrayPropertyUpdatedInLoopBody.kt
T
Dmitry Petrov e2fa613b70 Cache array length in for-in-array loop if possible
If the range expression is not a local variable (which can be updated in
the loop body affecting loop behavior, see KT-21354), we can cache the
array length, thus turning a for-in-array loop into a simple optimizable
counter loop.

 #KT-21321 In Progress
2017-11-29 10:15:32 +03:00

12 lines
212 B
Kotlin
Vendored

// WITH_RUNTIME
var xs = intArrayOf(1, 2, 3)
fun box(): String {
var sum = 0
for (x in xs) {
sum = sum * 10 + x
xs = IntArray(0)
}
return if (sum == 123) "OK" else "Fail: $sum"
}