diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java index 1fc9df399b9..194773fd18c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java @@ -1217,8 +1217,16 @@ public class AsmUtil { return JvmClassName.byFqNameWithoutInnerClasses(fqName).getInternalName(); } - public static void putJavaLangClassInstance(@NotNull InstructionAdapter v, @NotNull Type type) { - if (isPrimitive(type)) { + public static void putJavaLangClassInstance( + @NotNull InstructionAdapter v, + @NotNull Type type, + @Nullable KotlinType kotlinType, + @NotNull GenerationState state + ) { + if (kotlinType != null && InlineClassesUtilsKt.isInlineClassType(kotlinType)) { + v.aconst(boxType(type, kotlinType, state)); + } + else if (isPrimitive(type)) { v.getstatic(boxType(type).getInternalName(), "TYPE", "Ljava/lang/Class;"); } else { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java index dd712d1d0c6..118e6d4ebfc 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java @@ -402,7 +402,9 @@ public class ClosureCodegen extends MemberCodegen { if (container instanceof ClassDescriptor) { // TODO: would it work for arrays? - putJavaLangClassInstance(iv, state.getTypeMapper().mapClass((ClassDescriptor) container)); + SimpleType containerKotlinType = ((ClassDescriptor) container).getDefaultType(); + Type containerType = state.getTypeMapper().mapClass((ClassDescriptor) container); + putJavaLangClassInstance(iv, containerType, containerKotlinType, state); } else if (container instanceof PackageFragmentDescriptor) { iv.aconst(state.getTypeMapper().mapOwner(descriptor)); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 0da7f511d8e..3d2d217a2e0 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -3123,7 +3123,7 @@ public class ExpressionCodegen extends KtVisitor impleme putReifiedOperationMarkerIfTypeIsReifiedParameter(type, ReifiedTypeInliner.OperationKind.JAVA_CLASS); } - putJavaLangClassInstance(v, typeMapper.mapType(type)); + putJavaLangClassInstance(v, typeMapper.mapType(type), type, state); } if (wrapIntoKClass) { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index dac8dba3c86..eb3dddf10d9 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -1053,16 +1053,16 @@ class ExpressionCodegen( } else { val classType = classReference.classType if (classType is CrIrType) { - putJavaLangClassInstance(mv, classType.type) + putJavaLangClassInstance(mv, classType.type, null, state) return } else { - val type = classType.toKotlinType() - if (TypeUtils.isTypeParameter(type)) { - assert(TypeUtils.isReifiedTypeParameter(type)) { "Non-reified type parameter under ::class should be rejected by type checker: " + type } - putReifiedOperationMarkerIfTypeIsReifiedParameter(type, ReifiedTypeInliner.OperationKind.JAVA_CLASS, mv, this) + val kotlinType = classType.toKotlinType() + if (TypeUtils.isTypeParameter(kotlinType)) { + assert(TypeUtils.isReifiedTypeParameter(kotlinType)) { "Non-reified type parameter under ::class should be rejected by type checker: " + kotlinType } + putReifiedOperationMarkerIfTypeIsReifiedParameter(kotlinType, ReifiedTypeInliner.OperationKind.JAVA_CLASS, mv, this) } - putJavaLangClassInstance(mv, typeMapper.mapType(type)) + putJavaLangClassInstance(mv, typeMapper.mapType(kotlinType), kotlinType, state) } } diff --git a/compiler/testData/codegen/box/inlineClasses/classLiteralOnInlineClass.kt b/compiler/testData/codegen/box/inlineClasses/classLiteralOnInlineClass.kt index 93a1478bb9b..1697f9cc15c 100644 --- a/compiler/testData/codegen/box/inlineClasses/classLiteralOnInlineClass.kt +++ b/compiler/testData/codegen/box/inlineClasses/classLiteralOnInlineClass.kt @@ -63,5 +63,11 @@ fun box(): String { val arrU = arrayOf(1u) check(arrU[0]::class, "class kotlin.UInt") + check(IcInt::class, "class root.IcInt") + check(IcLong::class, "class root.IcLong") + check(IcAny::class, "class root.IcAny") + check(IcOverIc::class, "class root.IcOverIc") + check(UInt::class, "class kotlin.UInt") + return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/box/reflection/mapping/types/inlineClassInSignature.kt b/compiler/testData/codegen/box/reflection/mapping/types/inlineClassInSignature.kt index 4479a8e7542..de7b92d5563 100644 --- a/compiler/testData/codegen/box/reflection/mapping/types/inlineClassInSignature.kt +++ b/compiler/testData/codegen/box/reflection/mapping/types/inlineClassInSignature.kt @@ -16,7 +16,7 @@ inline class T(val s: S) { fun box(): String { assertEquals(listOf(String::class.java, Int::class.java, String::class.java), S::foo.parameters.map { it.type.javaType }) - assertEquals(S::class.java, S::foo.returnType.javaType) + assertEquals(String::class.java, S::foo.returnType.javaType) /* assertEquals(listOf(), T::bar.parameters.map { it.type.javaType })