Files
kotlin-fork/compiler/testData/codegen/box/ranges/forInCharSequenceLengthDecreasedInLoopBody.kt
T
Mark Punzalan c16b59191b Do not cache "last" value (i.e., size/length) in lowered for-loop
iteration over CharSequences.

CharSequences may be mutable (e.g., StringBuilder) and therefore its
contents and length can change within the loop.
2019-09-27 13:44:40 +02:00

16 lines
316 B
Kotlin
Vendored

// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
import kotlin.test.*
fun box(): String {
val sb = StringBuilder("1234")
val result = StringBuilder()
for (c in sb) {
sb.clear()
result.append(c)
}
assertEquals("", sb.toString())
assertEquals("1", result.toString())
return "OK"
}