JVM_IR reuse loop variable as index variable should happen after LDL

We can't apply "reuse loop variable as index variable" transformation
before local declarations lowering, otherwise it will affect captured
loop variable behavior, resulting in KT-48626.

Since it's JVM-specific, move it to JvmOptimizationLowering.
This commit is contained in:
Dmitry Petrov
2021-09-06 16:42:02 +03:00
committed by TeamCityServer
parent f62ffeaa0a
commit d9e4dec810
19 changed files with 445 additions and 133 deletions
@@ -0,0 +1,19 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: STDLIB_GENERATED
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
fun test(xs: List<String>): String {
var r = ""
for ((i, x) in xs.withIndex()) {
if (i > 1) break
r += "$i:$x;"
}
return r
}
fun box(): String {
val t = test(listOf("a", "b", "c", "d", "e"))
if (t != "0:a;1:b;") return "Failed: $t"
return "OK"
}
@@ -0,0 +1,19 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: STDLIB_GENERATED
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
fun test(xs: List<String>): String {
var r = ""
for ((i, x) in xs.withIndex()) {
if (i % 2 == 0) continue
r += "$i:$x;"
}
return r
}
fun box(): String {
val t = test(listOf("a", "b", "c", "d", "e"))
if (t != "1:b;3:d;") return "Failed: $t"
return "OK"
}