Fix for-in iterator over array of boxed inline class values
#KT-25324 Fixed
This commit is contained in:
@@ -15,6 +15,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.builtins.PrimitiveType;
|
import org.jetbrains.kotlin.builtins.PrimitiveType;
|
||||||
|
import org.jetbrains.kotlin.builtins.UnsignedTypes;
|
||||||
import org.jetbrains.kotlin.codegen.binding.CalculatedClosure;
|
import org.jetbrains.kotlin.codegen.binding.CalculatedClosure;
|
||||||
import org.jetbrains.kotlin.codegen.context.CodegenContext;
|
import org.jetbrains.kotlin.codegen.context.CodegenContext;
|
||||||
import org.jetbrains.kotlin.codegen.intrinsics.HashCode;
|
import org.jetbrains.kotlin.codegen.intrinsics.HashCode;
|
||||||
@@ -113,8 +114,27 @@ public class AsmUtil {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Type boxType(@NotNull Type type) {
|
public static Type boxType(@NotNull Type type) {
|
||||||
|
Type boxedType = boxPrimitiveType(type);
|
||||||
|
return boxedType != null ? boxedType : type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Type boxType(@NotNull Type type, @NotNull KotlinType kotlinType, @NotNull GenerationState state) {
|
||||||
|
Type boxedPrimitiveType = boxPrimitiveType(type);
|
||||||
|
if (boxedPrimitiveType != null) return boxedPrimitiveType;
|
||||||
|
|
||||||
|
if (InlineClassesUtilsKt.isInlineClassType(kotlinType)) {
|
||||||
|
return state.getTypeMapper().mapTypeAsDeclaration(kotlinType);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static Type boxPrimitiveType(@NotNull Type type) {
|
||||||
JvmPrimitiveType jvmPrimitiveType = primitiveTypeByAsmSort.get(type.getSort());
|
JvmPrimitiveType jvmPrimitiveType = primitiveTypeByAsmSort.get(type.getSort());
|
||||||
return jvmPrimitiveType != null ? asmTypeByFqNameWithoutInnerClasses(jvmPrimitiveType.getWrapperFqName()) : type;
|
return jvmPrimitiveType != null ? asmTypeByFqNameWithoutInnerClasses(jvmPrimitiveType.getWrapperFqName()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+3
-2
@@ -78,12 +78,13 @@ class ForInArrayLoopGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun assignToLoopParameter() {
|
override fun assignToLoopParameter() {
|
||||||
val arrayElParamType = if (KotlinBuiltIns.isArray(loopRangeType)) boxType(asmElementType) else asmElementType
|
val arrayElParamType =
|
||||||
|
if (KotlinBuiltIns.isArray(loopRangeType)) boxType(asmElementType, elementType, codegen.state) else asmElementType
|
||||||
|
|
||||||
v.load(arrayVar, OBJECT_TYPE)
|
v.load(arrayVar, OBJECT_TYPE)
|
||||||
v.load(indexVar, Type.INT_TYPE)
|
v.load(indexVar, Type.INT_TYPE)
|
||||||
v.aload(arrayElParamType)
|
v.aload(arrayElParamType)
|
||||||
StackValue.onStack(arrayElParamType).put(asmElementType, codegen.v)
|
StackValue.onStack(arrayElParamType, elementType).put(asmElementType, elementType, codegen.v)
|
||||||
v.store(loopParameterVar, asmElementType)
|
v.store(loopParameterVar, asmElementType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
// !LANGUAGE: +InlineClasses
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// IGNORE_BACKEND: JS_IR
|
||||||
|
|
||||||
|
inline class Foo(val arg: Int)
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val arr = arrayOf(Foo(1), Foo(2))
|
||||||
|
var sum = 0
|
||||||
|
for (el in arr) {
|
||||||
|
sum += el.arg
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (sum != 3) "Fail" else "OK"
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
// WITH_UNSIGNED
|
||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// IGNORE_BACKEND: JS_IR
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var sum = 0u
|
||||||
|
for (el in arrayOf(1u, 2u, 3u)) {
|
||||||
|
sum += el
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sum != 6u) return "Fail 1"
|
||||||
|
|
||||||
|
sum = 0u
|
||||||
|
for (el in uintArrayOf(10u, 20u)) {
|
||||||
|
sum += el
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sum != 30u) return "Fail 2"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Generated
+10
@@ -11126,6 +11126,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("iterateOverArrayOfInlineClassValues.kt")
|
||||||
|
public void testIterateOverArrayOfInlineClassValues() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/iterateOverArrayOfInlineClassValues.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
||||||
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
||||||
@@ -21242,6 +21247,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||||
|
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("unsignedLiteralsWithSignedOverflow.kt")
|
@TestMetadata("unsignedLiteralsWithSignedOverflow.kt")
|
||||||
public void testUnsignedLiteralsWithSignedOverflow() throws Exception {
|
public void testUnsignedLiteralsWithSignedOverflow() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedLiteralsWithSignedOverflow.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedLiteralsWithSignedOverflow.kt");
|
||||||
|
|||||||
+10
@@ -11126,6 +11126,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("iterateOverArrayOfInlineClassValues.kt")
|
||||||
|
public void testIterateOverArrayOfInlineClassValues() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/iterateOverArrayOfInlineClassValues.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
||||||
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
||||||
@@ -21242,6 +21247,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||||
|
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("unsignedLiteralsWithSignedOverflow.kt")
|
@TestMetadata("unsignedLiteralsWithSignedOverflow.kt")
|
||||||
public void testUnsignedLiteralsWithSignedOverflow() throws Exception {
|
public void testUnsignedLiteralsWithSignedOverflow() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedLiteralsWithSignedOverflow.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedLiteralsWithSignedOverflow.kt");
|
||||||
|
|||||||
+10
@@ -11126,6 +11126,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("iterateOverArrayOfInlineClassValues.kt")
|
||||||
|
public void testIterateOverArrayOfInlineClassValues() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/iterateOverArrayOfInlineClassValues.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
||||||
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
||||||
@@ -21242,6 +21247,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||||
|
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("unsignedLiteralsWithSignedOverflow.kt")
|
@TestMetadata("unsignedLiteralsWithSignedOverflow.kt")
|
||||||
public void testUnsignedLiteralsWithSignedOverflow() throws Exception {
|
public void testUnsignedLiteralsWithSignedOverflow() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedLiteralsWithSignedOverflow.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedLiteralsWithSignedOverflow.kt");
|
||||||
|
|||||||
+10
@@ -9776,6 +9776,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("iterateOverArrayOfInlineClassValues.kt")
|
||||||
|
public void testIterateOverArrayOfInlineClassValues() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/iterateOverArrayOfInlineClassValues.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
||||||
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
||||||
@@ -19252,6 +19257,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/unsignedTypes"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/unsignedTypes"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||||
|
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("varargsOfUnsignedTypes.kt")
|
@TestMetadata("varargsOfUnsignedTypes.kt")
|
||||||
public void testVarargsOfUnsignedTypes() throws Exception {
|
public void testVarargsOfUnsignedTypes() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/unsignedTypes/varargsOfUnsignedTypes.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/varargsOfUnsignedTypes.kt");
|
||||||
|
|||||||
+10
@@ -10771,6 +10771,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("iterateOverArrayOfInlineClassValues.kt")
|
||||||
|
public void testIterateOverArrayOfInlineClassValues() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/iterateOverArrayOfInlineClassValues.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
||||||
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
||||||
@@ -20247,6 +20252,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/unsignedTypes"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/unsignedTypes"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||||
|
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("varargsOfUnsignedTypes.kt")
|
@TestMetadata("varargsOfUnsignedTypes.kt")
|
||||||
public void testVarargsOfUnsignedTypes() throws Exception {
|
public void testVarargsOfUnsignedTypes() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/unsignedTypes/varargsOfUnsignedTypes.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/varargsOfUnsignedTypes.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user