Fix code generation for Array<C> element access where C is inline class
This commit is contained in:
@@ -4256,21 +4256,22 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
@Override
|
||||
public StackValue visitArrayAccessExpression(@NotNull KtArrayAccessExpression expression, StackValue receiver) {
|
||||
KtExpression array = expression.getArrayExpression();
|
||||
KotlinType type = array != null ? bindingContext.getType(array) : null;
|
||||
KotlinType arrayKotlinType = array != null ? bindingContext.getType(array) : null;
|
||||
Type arrayType = expressionType(array);
|
||||
List<KtExpression> indices = expression.getIndexExpressions();
|
||||
FunctionDescriptor operationDescriptor = (FunctionDescriptor) bindingContext.get(REFERENCE_TARGET, expression);
|
||||
assert operationDescriptor != null;
|
||||
boolean isInlineClassType = type != null && InlineClassesUtilsKt.isInlineClassType(type);
|
||||
boolean isInlineClassType = arrayKotlinType != null && InlineClassesUtilsKt.isInlineClassType(arrayKotlinType);
|
||||
if (arrayType.getSort() == Type.ARRAY &&
|
||||
indices.size() == 1 &&
|
||||
isInt(operationDescriptor.getValueParameters().get(0).getType()) &&
|
||||
!isInlineClassType) {
|
||||
assert type != null;
|
||||
!isInlineClassType
|
||||
) {
|
||||
assert arrayKotlinType != null;
|
||||
KotlinType elementKotlinType = state.getModule().getBuiltIns().getArrayElementType(arrayKotlinType);
|
||||
Type elementType;
|
||||
if (KotlinBuiltIns.isArray(type)) {
|
||||
KotlinType jetElementType = type.getArguments().get(0).getType();
|
||||
elementType = boxType(asmType(jetElementType));
|
||||
if (KotlinBuiltIns.isArray(arrayKotlinType)) {
|
||||
elementType = boxType(asmType(elementKotlinType), elementKotlinType, state);
|
||||
}
|
||||
else {
|
||||
elementType = correctElementType(arrayType);
|
||||
@@ -4278,7 +4279,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
StackValue arrayValue = genLazy(array, arrayType);
|
||||
StackValue index = genLazy(indices.get(0), Type.INT_TYPE);
|
||||
|
||||
return StackValue.arrayElement(elementType, null, arrayValue, index);
|
||||
return StackValue.arrayElement(elementType, elementKotlinType, arrayValue, index);
|
||||
}
|
||||
else {
|
||||
ResolvedCall<FunctionDescriptor> resolvedSetCall = bindingContext.get(INDEXED_LVALUE_SET, expression);
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR
|
||||
|
||||
inline class Z(val data: Int)
|
||||
|
||||
val xs = Array(2) { Z(42) }
|
||||
|
||||
fun box(): String {
|
||||
xs[0] = Z(12)
|
||||
val t = xs[0]
|
||||
if (t.data != 12) throw AssertionError("$t")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_UNSIGNED
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR, JS
|
||||
|
||||
val xs = Array(2) { 42u }
|
||||
|
||||
fun box(): String {
|
||||
xs[0] = 12u
|
||||
val t = xs[0]
|
||||
if (t != 12u) throw AssertionError("$t")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// WITH_UNSIGNED
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR, JS
|
||||
|
||||
inline class Data(val data: Array<UInt>)
|
||||
|
||||
val D =
|
||||
Array(4) { i ->
|
||||
Data(Array(4) { j ->
|
||||
(i + j).toUInt()
|
||||
})
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
for (i in D.indices) {
|
||||
for (j in D[i].data.indices) {
|
||||
val x = D[i].data[j].toInt()
|
||||
if (x != i + j) throw AssertionError()
|
||||
}
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+28
@@ -590,6 +590,34 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/arrays/varargsWithJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/arrays/arraysOfInlineClass")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ArraysOfInlineClass extends AbstractBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("accessArrayOfInlineClass.kt")
|
||||
public void testAccessArrayOfInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/accessArrayOfInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("accessArrayOfUnsigned.kt")
|
||||
public void testAccessArrayOfUnsigned() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/accessArrayOfUnsigned.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInArraysOfInlineClass() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/arraysOfInlineClass"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayOfInlineClassOfArrayOfInlineClass.kt")
|
||||
public void testArrayOfInlineClassOfArrayOfInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/arrayOfInlineClassOfArrayOfInlineClass.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/arrays/multiDecl")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+28
@@ -590,6 +590,34 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/arrays/varargsWithJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/arrays/arraysOfInlineClass")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ArraysOfInlineClass extends AbstractLightAnalysisModeTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("accessArrayOfInlineClass.kt")
|
||||
public void testAccessArrayOfInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/accessArrayOfInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("accessArrayOfUnsigned.kt")
|
||||
public void testAccessArrayOfUnsigned() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/accessArrayOfUnsigned.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInArraysOfInlineClass() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/arraysOfInlineClass"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayOfInlineClassOfArrayOfInlineClass.kt")
|
||||
public void testArrayOfInlineClassOfArrayOfInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/arrayOfInlineClassOfArrayOfInlineClass.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/arrays/multiDecl")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+28
@@ -590,6 +590,34 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/arrays/varargsWithJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/arrays/arraysOfInlineClass")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ArraysOfInlineClass extends AbstractIrBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("accessArrayOfInlineClass.kt")
|
||||
public void testAccessArrayOfInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/accessArrayOfInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("accessArrayOfUnsigned.kt")
|
||||
public void testAccessArrayOfUnsigned() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/accessArrayOfUnsigned.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInArraysOfInlineClass() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/arraysOfInlineClass"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayOfInlineClassOfArrayOfInlineClass.kt")
|
||||
public void testArrayOfInlineClassOfArrayOfInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/arrayOfInlineClassOfArrayOfInlineClass.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/arrays/multiDecl")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+28
@@ -580,6 +580,34 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/arrays/stdlib.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/arrays/arraysOfInlineClass")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ArraysOfInlineClass extends AbstractIrJsCodegenBoxTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("accessArrayOfInlineClass.kt")
|
||||
public void testAccessArrayOfInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/accessArrayOfInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("accessArrayOfUnsigned.kt")
|
||||
public void testAccessArrayOfUnsigned() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/accessArrayOfUnsigned.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInArraysOfInlineClass() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/arraysOfInlineClass"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayOfInlineClassOfArrayOfInlineClass.kt")
|
||||
public void testArrayOfInlineClassOfArrayOfInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/arrayOfInlineClassOfArrayOfInlineClass.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/arrays/multiDecl")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+28
@@ -580,6 +580,34 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/arrays/stdlib.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/arrays/arraysOfInlineClass")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ArraysOfInlineClass extends AbstractJsCodegenBoxTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("accessArrayOfInlineClass.kt")
|
||||
public void testAccessArrayOfInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/accessArrayOfInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("accessArrayOfUnsigned.kt")
|
||||
public void testAccessArrayOfUnsigned() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/accessArrayOfUnsigned.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInArraysOfInlineClass() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/arraysOfInlineClass"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayOfInlineClassOfArrayOfInlineClass.kt")
|
||||
public void testArrayOfInlineClassOfArrayOfInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/arrayOfInlineClassOfArrayOfInlineClass.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/arrays/multiDecl")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsLegacyPrimitiveArraysBoxTestGenerated.java
Generated
+28
@@ -329,6 +329,34 @@ public class JsLegacyPrimitiveArraysBoxTestGenerated extends AbstractJsLegacyPri
|
||||
runTest("compiler/testData/codegen/box/arrays/stdlib.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/arrays/arraysOfInlineClass")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ArraysOfInlineClass extends AbstractJsLegacyPrimitiveArraysBoxTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("accessArrayOfInlineClass.kt")
|
||||
public void testAccessArrayOfInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/accessArrayOfInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("accessArrayOfUnsigned.kt")
|
||||
public void testAccessArrayOfUnsigned() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/accessArrayOfUnsigned.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInArraysOfInlineClass() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/arraysOfInlineClass"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayOfInlineClassOfArrayOfInlineClass.kt")
|
||||
public void testArrayOfInlineClassOfArrayOfInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/arrays/arraysOfInlineClass/arrayOfInlineClassOfArrayOfInlineClass.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/arrays/multiDecl")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user