Fix unbound class literals for inline classes
#KT-28361 Fixed
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -402,7 +402,9 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
|
||||
|
||||
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));
|
||||
|
||||
@@ -3123,7 +3123,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
putReifiedOperationMarkerIfTypeIsReifiedParameter(type, ReifiedTypeInliner.OperationKind.JAVA_CLASS);
|
||||
}
|
||||
|
||||
putJavaLangClassInstance(v, typeMapper.mapType(type));
|
||||
putJavaLangClassInstance(v, typeMapper.mapType(type), type, state);
|
||||
}
|
||||
|
||||
if (wrapIntoKClass) {
|
||||
|
||||
+6
-6
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
+1
-1
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user