IC Mangling: Use correct java field type if the type is inline class

in old JVM BE.
 #KT-26445
This commit is contained in:
Ilmir Usmanov
2020-12-11 11:43:43 +01:00
parent 69bb65496f
commit 2b0a99b7b0
8 changed files with 127 additions and 7 deletions
@@ -54,6 +54,7 @@ import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor;
import org.jetbrains.kotlin.diagnostics.Errors;
import org.jetbrains.kotlin.lexer.KtTokens;
import org.jetbrains.kotlin.load.java.DescriptorsJvmAbiUtil;
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor;
import org.jetbrains.kotlin.load.kotlin.DescriptorBasedTypeSignatureMappingKt;
import org.jetbrains.kotlin.load.kotlin.MethodSignatureMappingKt;
import org.jetbrains.kotlin.name.Name;
@@ -2404,9 +2405,14 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
fieldName = KotlinTypeMapper.mapDefaultFieldName(propertyDescriptor, isDelegatedProperty);
}
KotlinType propertyType = propertyDescriptor.getOriginal().getType();
if (propertyDescriptor instanceof JavaPropertyDescriptor && InlineClassesUtilsKt.isInlineClassType(propertyType)) {
propertyType = TypeUtils.makeNullable(propertyType);
}
return StackValue.property(
propertyDescriptor, backingFieldOwner,
typeMapper.mapType(isDelegatedProperty && forceField ? delegateType : propertyDescriptor.getOriginal().getType()),
typeMapper.mapType(isDelegatedProperty && forceField ? delegateType : propertyType),
isStaticBackingField, fieldName, callableGetter, callableSetter, receiver, this, resolvedCall, skipLateinitAssertion,
isDelegatedProperty && forceField ? delegateType : null
);
@@ -4375,6 +4381,10 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
Type exprType = expressionType(expr);
KotlinType exprKotlinType = kotlinType(expr);
if (exprKotlinType != null && InlineClassesUtilsKt.isInlineClassType(exprKotlinType) &&
FlexibleTypesKt.isNullabilityFlexible(exprKotlinType)) {
exprKotlinType = TypeUtils.makeNullable(exprKotlinType);
}
StackValue value;
if (compileTimeConstant != null) {
value = StackValue.constant(compileTimeConstant.getValue(), exprType, exprKotlinType);
@@ -15129,6 +15129,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
public void testInlineClasInSignature() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/javaInterop/inlineClasInSignature.kt");
}
@TestMetadata("inlineClasInSignatureNonNull.kt")
public void testInlineClasInSignatureNonNull() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/javaInterop/inlineClasInSignatureNonNull.kt");
}
@TestMetadata("inlineClasInSignatureNullable.kt")
public void testInlineClasInSignatureNullable() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/javaInterop/inlineClasInSignatureNullable.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods")
@@ -5,16 +5,14 @@
// FILE: WithInlineClass.java
import kotlin.UInt;
import org.jetbrains.annotations.NotNull;
public class WithInlineClass {
private static UInt UINT = null;
public static UInt UINT = null;
public static void acceptsUInt(@NotNull UInt u) {
public static void acceptsUInt(UInt u) {
UINT = u;
}
@NotNull
public static UInt provideUInt() {
return UINT;
}
@@ -24,6 +22,10 @@ public class WithInlineClass {
fun box(): String {
WithInlineClass.acceptsUInt(1u)
val res = WithInlineClass.provideUInt()
return if (res == 1u) "OK" else "FAIL $res"
var res = WithInlineClass.provideUInt()
if (res != 1u) return "FAIL 1 $res"
WithInlineClass.UINT = 2u
res = WithInlineClass.UINT
if (res != 2u) return "FAIL 2 $res"
return "OK"
}
@@ -0,0 +1,34 @@
// LANGUAGE: +InlineClasses
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: WithInlineClass.java
import kotlin.UInt;
import org.jetbrains.annotations.NotNull;
public class WithInlineClass {
@NotNull
public static UInt UINT = null;
public static void acceptsUInt(@NotNull UInt u) {
UINT = u;
}
@NotNull
public static UInt provideUInt() {
return UINT;
}
}
// FILE: box.kt
fun box(): String {
WithInlineClass.acceptsUInt(1u)
var res = WithInlineClass.provideUInt()
if (res != 1u) return "FAIL 1 $res"
WithInlineClass.UINT = 2u
res = WithInlineClass.UINT
if (res != 2u) return "FAIL 2 $res"
return "OK"
}
@@ -0,0 +1,34 @@
// LANGUAGE: +InlineClasses
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: WithInlineClass.java
import kotlin.UInt;
import org.jetbrains.annotations.Nullable;
public class WithInlineClass {
@Nullable
public static UInt UINT = null;
public static void acceptsUInt(@Nullable UInt u) {
UINT = u;
}
@Nullable
public static UInt provideUInt() {
return UINT;
}
}
// FILE: box.kt
fun box(): String {
WithInlineClass.acceptsUInt(1u)
var res = WithInlineClass.provideUInt()
if (res != 1u) return "FAIL 1 $res"
WithInlineClass.UINT = 2u
res = WithInlineClass.UINT
if (res != 2u) return "FAIL 2 $res"
return "OK"
}
@@ -15129,6 +15129,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testInlineClasInSignature() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/javaInterop/inlineClasInSignature.kt");
}
@TestMetadata("inlineClasInSignatureNonNull.kt")
public void testInlineClasInSignatureNonNull() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/javaInterop/inlineClasInSignatureNonNull.kt");
}
@TestMetadata("inlineClasInSignatureNullable.kt")
public void testInlineClasInSignatureNullable() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/javaInterop/inlineClasInSignatureNullable.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods")
@@ -15129,6 +15129,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
public void testInlineClasInSignature() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/javaInterop/inlineClasInSignature.kt");
}
@TestMetadata("inlineClasInSignatureNonNull.kt")
public void testInlineClasInSignatureNonNull() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/javaInterop/inlineClasInSignatureNonNull.kt");
}
@TestMetadata("inlineClasInSignatureNullable.kt")
public void testInlineClasInSignatureNullable() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/javaInterop/inlineClasInSignatureNullable.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods")
@@ -15129,6 +15129,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
public void testInlineClasInSignature() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/javaInterop/inlineClasInSignature.kt");
}
@TestMetadata("inlineClasInSignatureNonNull.kt")
public void testInlineClasInSignatureNonNull() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/javaInterop/inlineClasInSignatureNonNull.kt");
}
@TestMetadata("inlineClasInSignatureNullable.kt")
public void testInlineClasInSignatureNullable() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/javaInterop/inlineClasInSignatureNullable.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods")