Handle withIndex() on arrays and CharSequences in ForLoopsLowering.

This commit is contained in:
Mark Punzalan
2019-11-04 16:13:56 -08:00
committed by max-kammerer
parent 735535dd5a
commit a54d9482dd
25 changed files with 633 additions and 142 deletions
@@ -0,0 +1,15 @@
// IGNORE_BACKEND_FIR: JVM_IR
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
val arr = arrayOf("a", "b", "c", "d")
fun box(): String {
var count = 0
for ((_, _) in arr.withIndex()) {
count++
}
return if (count == 4) "OK" else "fail: '$count'"
}
@@ -0,0 +1,17 @@
// IGNORE_BACKEND_FIR: JVM_IR
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
val arr = arrayOf("a", "b", "c", "d")
fun box(): String {
val s = StringBuilder()
for (iv in arr.withIndex()) {
val (i, x) = iv
s.append("$i:$x;")
}
val ss = s.toString()
return if (ss == "0:a;1:b;2:c;3:d;") "OK" else "fail: '$ss'"
}
@@ -0,0 +1,15 @@
// IGNORE_BACKEND_FIR: JVM_IR
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
val xs = "abcd"
fun box(): String {
var count = 0
for ((_, _) in xs.withIndex()) {
count++
}
return if (count == 4) "OK" else "fail: '$count'"
}
@@ -0,0 +1,15 @@
// IGNORE_BACKEND_FIR: JVM_IR
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
fun box(): String {
val s = StringBuilder()
for (iv in "abcd".withIndex()) {
val (index, x) = iv
s.append("$index:$x;")
}
val ss = s.toString()
return if (ss == "0:a;1:b;2:c;3:d;") "OK" else "fail: '$ss'"
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
val arr = arrayOf("a", "b", "c", "d")
fun box(): String {
@@ -19,3 +18,6 @@ fun box(): String {
// 0 component1
// 0 component2
// 1 ARRAYLENGTH
// The 1st ICONST_0 is for initializing the array. 2nd is for initializing the index in the lowered for-loop.
// 2 ICONST_0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
val arr = arrayOf("a", "b", "c", "d")
fun box(): String {
@@ -19,3 +18,6 @@ fun box(): String {
// 0 component1
// 0 component2
// 1 ARRAYLENGTH
// The 1st ICONST_0 is for initializing the array. 2nd is for initializing the index in the lowered for-loop.
// 2 ICONST_0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
val arr = intArrayOf()
fun box(): String {
@@ -16,3 +15,6 @@ fun box(): String {
// 0 component1
// 0 component2
// 1 ARRAYLENGTH
// The 1st ICONST_0 is for initializing the array. 2nd is for initializing the index in the lowered for-loop.
// 2 ICONST_0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
val arr = intArrayOf(10, 20, 30, 40)
fun box(): String {
@@ -17,3 +16,6 @@ fun box(): String {
// 0 component1
// 0 component2
// 1 ARRAYLENGTH
// The 1st ICONST_0 is for initializing the array. 2nd is for initializing the index in the lowered for-loop.
// 2 ICONST_0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
val arr = arrayOf("a", "b", "c", "d")
fun box(): String {
@@ -19,3 +18,6 @@ fun box(): String {
// 0 component1
// 0 component2
// 1 ARRAYLENGTH
// The 1st ICONST_0 is for initializing the array. 2nd is for initializing the index in the lowered for-loop.
// 2 ICONST_0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
val cs: CharSequence = "abcd"
fun box(): String {
@@ -20,3 +19,6 @@ fun box(): String {
// 0 component2
// 1 length
// 1 charAt
// The ICONST_0 is for initializing the index in the lowered for-loop.
// 1 ICONST_0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
fun box(): String {
for ((index, x) in "".withIndex()) {
return "Loop over empty String should not be executed"
@@ -14,3 +13,6 @@ fun box(): String {
// 0 component2
// 1 length
// 1 charAt
// The ICONST_0 is for initializing the index in the lowered for-loop.
// 1 ICONST_0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
fun box(): String {
val s = StringBuilder()
@@ -18,3 +17,6 @@ fun box(): String {
// 0 component2
// 1 length
// 1 charAt
// The ICONST_0 is for initializing the index in the lowered for-loop.
// 1 ICONST_0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
val xs = "abcd"
fun box(): String {
@@ -20,3 +19,6 @@ fun box(): String {
// 0 component2
// 1 length
// 1 charAt
// The ICONST_0 is for initializing the index in the lowered for-loop.
// 1 ICONST_0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
val xs = "abcd"
fun box(): String {
@@ -20,3 +19,6 @@ fun box(): String {
// 0 component2
// 1 length
// 1 charAt
// The ICONST_0 is for initializing the index in the lowered for-loop.
// 1 ICONST_0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
val xs = "abcd"
fun useAny(x: Any) {}
@@ -23,3 +22,6 @@ fun box(): String {
// 0 component2
// 1 length
// 1 charAt
// The ICONST_0 is for initializing the index in the lowered for-loop.
// 1 ICONST_0