Add test for array modification within for-in-array-withIndex loop body
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
// See https://youtrack.jetbrains.com/issue/KT-22424
|
||||
// IGNORE_BACKEND: JS
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun testUnoptimized(): String {
|
||||
var arr = intArrayOf(1, 2, 3, 4)
|
||||
val sb = StringBuilder()
|
||||
val ixs = arr.withIndex()
|
||||
for ((i, x) in ixs) {
|
||||
sb.append("$i:$x;")
|
||||
arr = intArrayOf(10, 20)
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val tn = testUnoptimized()
|
||||
|
||||
var arr = intArrayOf(1, 2, 3, 4)
|
||||
val sb = StringBuilder()
|
||||
for ((i, x) in arr.withIndex()) {
|
||||
sb.append("$i:$x;")
|
||||
arr = intArrayOf(10, 20)
|
||||
}
|
||||
|
||||
val s = sb.toString()
|
||||
if (s != "0:1;1:2;2:3;3:4;") return "Fail: '$s'; unoptimized: '$tn'"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Generated
+6
@@ -5186,6 +5186,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("forInArrayWithIndexContinuesAsUnmodified.kt")
|
||||
public void testForInArrayWithIndexContinuesAsUnmodified() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayWithIndexContinuesAsUnmodified.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInArrrayWithIndexNoElementVar.kt")
|
||||
public void testForInArrrayWithIndexNoElementVar() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrrayWithIndexNoElementVar.kt");
|
||||
|
||||
+6
@@ -5186,6 +5186,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("forInArrayWithIndexContinuesAsUnmodified.kt")
|
||||
public void testForInArrayWithIndexContinuesAsUnmodified() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayWithIndexContinuesAsUnmodified.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInArrrayWithIndexNoElementVar.kt")
|
||||
public void testForInArrrayWithIndexNoElementVar() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrrayWithIndexNoElementVar.kt");
|
||||
|
||||
+6
@@ -5186,6 +5186,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("forInArrayWithIndexContinuesAsUnmodified.kt")
|
||||
public void testForInArrayWithIndexContinuesAsUnmodified() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayWithIndexContinuesAsUnmodified.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInArrrayWithIndexNoElementVar.kt")
|
||||
public void testForInArrrayWithIndexNoElementVar() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrrayWithIndexNoElementVar.kt");
|
||||
|
||||
+12
@@ -5768,6 +5768,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("forInArrayWithIndexContinuesAsUnmodified.kt")
|
||||
public void testForInArrayWithIndexContinuesAsUnmodified() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayWithIndexContinuesAsUnmodified.kt");
|
||||
try {
|
||||
doTest(fileName);
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
return;
|
||||
}
|
||||
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||
}
|
||||
|
||||
@TestMetadata("forInArrrayWithIndexNoElementVar.kt")
|
||||
public void testForInArrrayWithIndexNoElementVar() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrrayWithIndexNoElementVar.kt");
|
||||
|
||||
Reference in New Issue
Block a user