Support inline classes in javaObjectType/javaPrimitiveType
#KT-28290 Fixed Target versions 1.3.30
This commit is contained in:
@@ -454,6 +454,11 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
return typeMapper.mapType(type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type mapTypeAsDeclaration(@NotNull KotlinType type) {
|
||||
return typeMapper.mapTypeAsDeclaration(type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type expressionType(@Nullable KtExpression expression) {
|
||||
return CodegenUtilKt.asmType(expression, typeMapper, bindingContext);
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ class KClassJavaObjectTypeProperty : IntrinsicPropertyGetter() {
|
||||
}
|
||||
codegen.putReifiedOperationMarkerIfTypeIsReifiedParameter(lhs.type, ReifiedTypeInliner.OperationKind.JAVA_CLASS)
|
||||
}
|
||||
iv.aconst(AsmUtil.boxType(codegen.asmType(lhs.type)))
|
||||
iv.aconst(AsmUtil.boxType(codegen.mapTypeAsDeclaration(lhs.type)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-5
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.psi.KtClassLiteralExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext.DOUBLE_COLON_LHS
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.isInlineClassType
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
@@ -32,21 +33,28 @@ class KClassJavaPrimitiveTypeProperty : IntrinsicPropertyGetter() {
|
||||
val receiverType = codegen.bindingContext.getType(receiverExpression) ?: return null
|
||||
if (!KotlinBuiltIns.isPrimitiveTypeOrNullablePrimitiveType(receiverType)) return null
|
||||
}
|
||||
|
||||
val lhsType = codegen.asmType(lhs.type)
|
||||
return StackValue.operation(returnType) { iv ->
|
||||
when {
|
||||
lhs is DoubleColonLHS.Expression && !lhs.isObjectQualifier -> {
|
||||
codegen.gen(receiverExpression).put(lhsType, iv)
|
||||
AsmUtil.pop(iv, lhsType)
|
||||
if (lhs.type.isInlineClassType())
|
||||
iv.aconst(null)
|
||||
else
|
||||
iv.getstatic(AsmUtil.boxType(lhsType).internalName, "TYPE", "Ljava/lang/Class;")
|
||||
}
|
||||
|
||||
!lhs.type.isInlineClassType() && isPrimitiveOrWrapper(lhsType) -> {
|
||||
iv.getstatic(AsmUtil.boxType(lhsType).internalName, "TYPE", "Ljava/lang/Class;")
|
||||
}
|
||||
AsmUtil.isPrimitive(lhsType) ||
|
||||
AsmUtil.unboxPrimitiveTypeOrNull(lhsType) != null ||
|
||||
AsmTypes.VOID_WRAPPER_TYPE == lhsType -> {
|
||||
iv.getstatic(AsmUtil.boxType(lhsType).internalName, "TYPE", "Ljava/lang/Class;")
|
||||
}
|
||||
|
||||
else -> iv.aconst(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isPrimitiveOrWrapper(lhsType: Type) =
|
||||
AsmUtil.isPrimitive(lhsType) || AsmUtil.unboxPrimitiveTypeOrNull(lhsType) != null || AsmTypes.VOID_WRAPPER_TYPE == lhsType
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
val c = UInt::class.javaObjectType
|
||||
val x = c.cast(123u)
|
||||
|
||||
if (x != 123u) throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
if (UInt::class.javaPrimitiveType != null) throw AssertionError()
|
||||
return "OK"
|
||||
}
|
||||
+10
@@ -12160,6 +12160,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28879.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt28920_javaObjectType.kt")
|
||||
public void testKt28920_javaObjectType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaObjectType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt28920_javaPrimitiveType.kt")
|
||||
public void testKt28920_javaPrimitiveType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaPrimitiveType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
|
||||
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
|
||||
|
||||
+10
@@ -12160,6 +12160,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28879.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt28920_javaObjectType.kt")
|
||||
public void testKt28920_javaObjectType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaObjectType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt28920_javaPrimitiveType.kt")
|
||||
public void testKt28920_javaPrimitiveType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaPrimitiveType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
|
||||
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
|
||||
|
||||
+10
@@ -12165,6 +12165,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28879.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt28920_javaObjectType.kt")
|
||||
public void testKt28920_javaObjectType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaObjectType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt28920_javaPrimitiveType.kt")
|
||||
public void testKt28920_javaPrimitiveType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaPrimitiveType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mapInlineClassesWithSuppressWildcardsMode.kt")
|
||||
public void testMapInlineClassesWithSuppressWildcardsMode() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mapInlineClassesWithSuppressWildcardsMode.kt");
|
||||
|
||||
Reference in New Issue
Block a user