Fix boxing/unboxing for generic functions on index expressions
Unsubstituted type should be used for coercion to box value of inline class type if it's needed. For the substituted value it's not known if it was a generic parameter or not. #KT-27502 Fixed
This commit is contained in:
@@ -4370,8 +4370,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
|
||||
Type elementType = isGetter ? callableMethod.getReturnType() : ArrayUtil.getLastElement(argumentTypes);
|
||||
KotlinType elementKotlinType = isGetter ?
|
||||
operationDescriptor.getReturnType() :
|
||||
CollectionsKt.last(operationDescriptor.getValueParameters()).getType();
|
||||
operationDescriptor.getOriginal().getReturnType() :
|
||||
CollectionsKt.last(operationDescriptor.getOriginal().getValueParameters()).getType();
|
||||
return StackValue.collectionElement(
|
||||
collectionElementReceiver, elementType, elementKotlinType, resolvedGetCall, resolvedSetCall, this
|
||||
);
|
||||
|
||||
@@ -1449,7 +1449,7 @@ public abstract class StackValue {
|
||||
|
||||
Type lastParameterType = ArraysKt.last(setter.getParameterTypes());
|
||||
KotlinType lastParameterKotlinType =
|
||||
CollectionsKt.last(resolvedSetCall.getResultingDescriptor().getValueParameters()).getType();
|
||||
CollectionsKt.last(resolvedSetCall.getResultingDescriptor().getOriginal().getValueParameters()).getType();
|
||||
|
||||
coerce(topOfStackType, topOfStackKotlinType, lastParameterType, lastParameterKotlinType, v);
|
||||
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
inline class NullableInt(private val holder: Any?) {
|
||||
val intValue: Int get() = holder as Int
|
||||
}
|
||||
|
||||
val prop: ArrayList<NullableInt> = arrayListOf(NullableInt(0))
|
||||
|
||||
fun box(): String {
|
||||
val a = prop[0].intValue
|
||||
if (a != 0) return "Error 1: $a"
|
||||
|
||||
val local = mutableListOf(NullableInt(1))
|
||||
val b = local[0].intValue
|
||||
if (b != 1) return "Error 2: $b"
|
||||
|
||||
prop[0] = NullableInt(2)
|
||||
if (prop[0].intValue != 2) return "Error 3: ${prop[0].intValue}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -11984,6 +11984,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unboxValueOfAnyBeforeMethodInvocation.kt")
|
||||
public void testUnboxValueOfAnyBeforeMethodInvocation() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxValueOfAnyBeforeMethodInvocation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("useInlineClassesInsideElvisOperator.kt")
|
||||
public void testUseInlineClassesInsideElvisOperator() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt");
|
||||
|
||||
+5
@@ -11984,6 +11984,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unboxValueOfAnyBeforeMethodInvocation.kt")
|
||||
public void testUnboxValueOfAnyBeforeMethodInvocation() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxValueOfAnyBeforeMethodInvocation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("useInlineClassesInsideElvisOperator.kt")
|
||||
public void testUseInlineClassesInsideElvisOperator() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt");
|
||||
|
||||
+5
@@ -11989,6 +11989,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unboxValueOfAnyBeforeMethodInvocation.kt")
|
||||
public void testUnboxValueOfAnyBeforeMethodInvocation() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxValueOfAnyBeforeMethodInvocation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("useInlineClassesInsideElvisOperator.kt")
|
||||
public void testUseInlineClassesInsideElvisOperator() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt");
|
||||
|
||||
+5
-5
@@ -5160,11 +5160,6 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/createCoroutineSafe.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
||||
public void testCreateCoroutinesOnManualInstances() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("createCoroutinesOnManualInstances_1_2.kt")
|
||||
public void testCreateCoroutinesOnManualInstances_1_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances_1_2.kt");
|
||||
@@ -10524,6 +10519,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unboxValueOfAnyBeforeMethodInvocation.kt")
|
||||
public void testUnboxValueOfAnyBeforeMethodInvocation() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxValueOfAnyBeforeMethodInvocation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("useInlineClassesInsideElvisOperator.kt")
|
||||
public void testUseInlineClassesInsideElvisOperator() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt");
|
||||
|
||||
+5
-5
@@ -5245,11 +5245,6 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/createCoroutineSafe.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
||||
public void testCreateCoroutinesOnManualInstances() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("createCoroutinesOnManualInstances_1_2.kt")
|
||||
public void testCreateCoroutinesOnManualInstances_1_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances_1_2.kt");
|
||||
@@ -11569,6 +11564,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxValueFromPlatformType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unboxValueOfAnyBeforeMethodInvocation.kt")
|
||||
public void testUnboxValueOfAnyBeforeMethodInvocation() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxValueOfAnyBeforeMethodInvocation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("useInlineClassesInsideElvisOperator.kt")
|
||||
public void testUseInlineClassesInsideElvisOperator() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt");
|
||||
|
||||
Reference in New Issue
Block a user