Use correctElementType to determine array element type for withIndex
Rather unkind "gotcha" in ASM API. #KT-23900 Fixed Target versions 1.2.50
This commit is contained in:
+2
-1
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.range.forLoop
|
package org.jetbrains.kotlin.codegen.range.forLoop
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||||
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
||||||
import org.jetbrains.kotlin.codegen.StackValue
|
import org.jetbrains.kotlin.codegen.StackValue
|
||||||
import org.jetbrains.kotlin.codegen.generateCallReceiver
|
import org.jetbrains.kotlin.codegen.generateCallReceiver
|
||||||
@@ -24,7 +25,7 @@ class ArrayWithIndexForLoopGenerator(
|
|||||||
) : AbstractWithIndexForLoopGenerator(codegen, forExpression, loopParameter, rangeCall) {
|
) : AbstractWithIndexForLoopGenerator(codegen, forExpression, loopParameter, rangeCall) {
|
||||||
|
|
||||||
private val arrayType = codegen.asmType(ExpressionCodegen.getExpectedReceiverType(rangeCall))
|
private val arrayType = codegen.asmType(ExpressionCodegen.getExpectedReceiverType(rangeCall))
|
||||||
private val arrayElementType = arrayType.elementType
|
private val arrayElementType = AsmUtil.correctElementType(arrayType)
|
||||||
private var arrayVar = -1
|
private var arrayVar = -1
|
||||||
private var arrayLengthVar = -1
|
private var arrayLengthVar = -1
|
||||||
|
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val arr = Array(4) { arrayOf("x$it") }
|
||||||
|
|
||||||
|
var s = ""
|
||||||
|
for ((i, sarr) in arr.withIndex()) {
|
||||||
|
s += "$i:${sarr.toList()}"
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (s != "0:[x0]1:[x1]2:[x2]3:[x3]") "Fail: '$s'" else "OK"
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
// [[0], [1], [2], [3]]
|
||||||
|
val arr = Array(4) { intArrayOf(it) }
|
||||||
|
|
||||||
|
var s = 0
|
||||||
|
for ((i, iarr) in arr.withIndex()) {
|
||||||
|
s += i*iarr[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0 + 1 + 4 + 9 = 14
|
||||||
|
return if (s != 14) "Fail: $s" else "OK"
|
||||||
|
}
|
||||||
Generated
+11
-2
@@ -4627,6 +4627,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInArrayOfObjectArrayWithIndex.kt")
|
||||||
|
public void testForInArrayOfObjectArrayWithIndex() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayOfObjectArrayWithIndex.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInArrayOfPrimArrayWithIndex.kt")
|
||||||
|
public void testForInArrayOfPrimArrayWithIndex() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayOfPrimArrayWithIndex.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("forInArrayWithIndexContinuesAsUnmodified.kt")
|
@TestMetadata("forInArrayWithIndexContinuesAsUnmodified.kt")
|
||||||
public void testForInArrayWithIndexContinuesAsUnmodified() throws Exception {
|
public void testForInArrayWithIndexContinuesAsUnmodified() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayWithIndexContinuesAsUnmodified.kt");
|
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayWithIndexContinuesAsUnmodified.kt");
|
||||||
@@ -13814,8 +13824,7 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
|
|
||||||
@TestMetadata("kt23260.kt")
|
@TestMetadata("kt23260.kt")
|
||||||
public void testKt23260() throws Exception {
|
public void testKt23260() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/properties/lateinit/local/kt23260.kt");
|
runTest("compiler/testData/codegen/box/properties/lateinit/local/kt23260.kt");
|
||||||
doTest(fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("localLateinit.kt")
|
@TestMetadata("localLateinit.kt")
|
||||||
|
|||||||
+11
-2
@@ -4627,6 +4627,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInArrayOfObjectArrayWithIndex.kt")
|
||||||
|
public void testForInArrayOfObjectArrayWithIndex() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayOfObjectArrayWithIndex.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInArrayOfPrimArrayWithIndex.kt")
|
||||||
|
public void testForInArrayOfPrimArrayWithIndex() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayOfPrimArrayWithIndex.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("forInArrayWithIndexContinuesAsUnmodified.kt")
|
@TestMetadata("forInArrayWithIndexContinuesAsUnmodified.kt")
|
||||||
public void testForInArrayWithIndexContinuesAsUnmodified() throws Exception {
|
public void testForInArrayWithIndexContinuesAsUnmodified() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayWithIndexContinuesAsUnmodified.kt");
|
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayWithIndexContinuesAsUnmodified.kt");
|
||||||
@@ -13814,8 +13824,7 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
|
|
||||||
@TestMetadata("kt23260.kt")
|
@TestMetadata("kt23260.kt")
|
||||||
public void testKt23260() throws Exception {
|
public void testKt23260() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/properties/lateinit/local/kt23260.kt");
|
runTest("compiler/testData/codegen/box/properties/lateinit/local/kt23260.kt");
|
||||||
doTest(fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("localLateinit.kt")
|
@TestMetadata("localLateinit.kt")
|
||||||
|
|||||||
+1
-2
@@ -2559,8 +2559,7 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
|||||||
|
|
||||||
@TestMetadata("doNotAppendEmptyString.kt")
|
@TestMetadata("doNotAppendEmptyString.kt")
|
||||||
public void testDoNotAppendEmptyString() throws Exception {
|
public void testDoNotAppendEmptyString() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/stringOperations/doNotAppendEmptyString.kt");
|
runTest("compiler/testData/codegen/bytecodeText/stringOperations/doNotAppendEmptyString.kt");
|
||||||
doTest(fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("interpolation.kt")
|
@TestMetadata("interpolation.kt")
|
||||||
|
|||||||
+11
-2
@@ -4627,6 +4627,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInArrayOfObjectArrayWithIndex.kt")
|
||||||
|
public void testForInArrayOfObjectArrayWithIndex() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayOfObjectArrayWithIndex.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInArrayOfPrimArrayWithIndex.kt")
|
||||||
|
public void testForInArrayOfPrimArrayWithIndex() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayOfPrimArrayWithIndex.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("forInArrayWithIndexContinuesAsUnmodified.kt")
|
@TestMetadata("forInArrayWithIndexContinuesAsUnmodified.kt")
|
||||||
public void testForInArrayWithIndexContinuesAsUnmodified() throws Exception {
|
public void testForInArrayWithIndexContinuesAsUnmodified() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayWithIndexContinuesAsUnmodified.kt");
|
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayWithIndexContinuesAsUnmodified.kt");
|
||||||
@@ -13814,8 +13824,7 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
|
|
||||||
@TestMetadata("kt23260.kt")
|
@TestMetadata("kt23260.kt")
|
||||||
public void testKt23260() throws Exception {
|
public void testKt23260() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/properties/lateinit/local/kt23260.kt");
|
runTest("compiler/testData/codegen/box/properties/lateinit/local/kt23260.kt");
|
||||||
doTest(fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("localLateinit.kt")
|
@TestMetadata("localLateinit.kt")
|
||||||
|
|||||||
+11
-2
@@ -4397,6 +4397,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInArrayOfObjectArrayWithIndex.kt")
|
||||||
|
public void testForInArrayOfObjectArrayWithIndex() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayOfObjectArrayWithIndex.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInArrayOfPrimArrayWithIndex.kt")
|
||||||
|
public void testForInArrayOfPrimArrayWithIndex() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayOfPrimArrayWithIndex.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("forInArrayWithIndexContinuesAsUnmodified.kt")
|
@TestMetadata("forInArrayWithIndexContinuesAsUnmodified.kt")
|
||||||
public void testForInArrayWithIndexContinuesAsUnmodified() throws Exception {
|
public void testForInArrayWithIndexContinuesAsUnmodified() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayWithIndexContinuesAsUnmodified.kt");
|
runTest("compiler/testData/codegen/box/controlStructures/forInArrayWithIndex/forInArrayWithIndexContinuesAsUnmodified.kt");
|
||||||
@@ -13204,8 +13214,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
|
|
||||||
@TestMetadata("kt23260.kt")
|
@TestMetadata("kt23260.kt")
|
||||||
public void testKt23260() throws Exception {
|
public void testKt23260() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/properties/lateinit/local/kt23260.kt");
|
runTest("compiler/testData/codegen/box/properties/lateinit/local/kt23260.kt");
|
||||||
doTest(fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("localLateinit.kt")
|
@TestMetadata("localLateinit.kt")
|
||||||
|
|||||||
Reference in New Issue
Block a user