[IR BE] Fix array constructor loop. Use index parameter as immutable value
This commit is contained in:
+8
-3
@@ -80,11 +80,16 @@ class ArrayConstructorLowering(val context: CommonBackendContext) : IrElementTra
|
||||
putValueArgument(1, irGet(sizeVar))
|
||||
}
|
||||
body = irBlock {
|
||||
val value =
|
||||
lambda?.inline(listOf(index)) ?: irCallOp(invoke.symbol, invoke.returnType, irGet(invokableVar!!), irGet(index))
|
||||
val tempIndex = irTemporary(irGet(index))
|
||||
val value = lambda?.inline(listOf(tempIndex)) ?: irCallOp(
|
||||
invoke.symbol,
|
||||
invoke.returnType,
|
||||
irGet(invokableVar!!),
|
||||
irGet(tempIndex)
|
||||
)
|
||||
+irCall(result.type.getClass()!!.functions.single { it.name == OperatorNameConventions.SET }).apply {
|
||||
dispatchReceiver = irGet(result)
|
||||
putValueArgument(0, irGet(index))
|
||||
putValueArgument(0, irGet(tempIndex))
|
||||
putValueArgument(1, value)
|
||||
}
|
||||
val inc = index.type.getClass()!!.functions.single { it.name == OperatorNameConventions.INC }
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
||||
val size = 10
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val intArray = IntArray(size)
|
||||
|
||||
val array = Array(size) { i -> { intArray[i]++ } }
|
||||
|
||||
for (i in intArray) {
|
||||
assertEquals(0, i)
|
||||
}
|
||||
|
||||
for (a in array) {
|
||||
a()
|
||||
}
|
||||
|
||||
for (i in intArray) {
|
||||
assertEquals(1, i)
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -310,6 +310,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayConstructorWithNonInlineLambda.kt")
|
||||
public void testArrayConstructorWithNonInlineLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arrayConstructorWithNonInlineLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("arrayConstructorsSimple.kt")
|
||||
public void testArrayConstructorsSimple() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt");
|
||||
|
||||
+5
@@ -310,6 +310,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayConstructorWithNonInlineLambda.kt")
|
||||
public void testArrayConstructorWithNonInlineLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arrayConstructorWithNonInlineLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("arrayConstructorsSimple.kt")
|
||||
public void testArrayConstructorsSimple() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt");
|
||||
|
||||
+5
@@ -310,6 +310,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayConstructorWithNonInlineLambda.kt")
|
||||
public void testArrayConstructorWithNonInlineLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arrayConstructorWithNonInlineLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("arrayConstructorsSimple.kt")
|
||||
public void testArrayConstructorsSimple() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt");
|
||||
|
||||
Generated
+5
@@ -165,6 +165,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayConstructorWithNonInlineLambda.kt")
|
||||
public void testArrayConstructorWithNonInlineLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arrayConstructorWithNonInlineLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("arrayConstructorsSimple.kt")
|
||||
public void testArrayConstructorsSimple() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt");
|
||||
|
||||
+5
@@ -165,6 +165,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayConstructorWithNonInlineLambda.kt")
|
||||
public void testArrayConstructorWithNonInlineLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arrayConstructorWithNonInlineLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("arrayConstructorsSimple.kt")
|
||||
public void testArrayConstructorsSimple() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt");
|
||||
|
||||
js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsLegacyPrimitiveArraysBoxTestGenerated.java
Generated
+5
@@ -29,6 +29,11 @@ public class JsLegacyPrimitiveArraysBoxTestGenerated extends AbstractJsLegacyPri
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayConstructorWithNonInlineLambda.kt")
|
||||
public void testArrayConstructorWithNonInlineLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arrayConstructorWithNonInlineLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("arrayConstructorsSimple.kt")
|
||||
public void testArrayConstructorsSimple() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt");
|
||||
|
||||
Reference in New Issue
Block a user