KTIJ-24768 Fix IllegalArgumentException in KtType.isPrimitiveBacked

This commit is contained in:
Pavel Mikhailovskii
2023-03-10 11:03:45 +00:00
committed by Space Team
parent 8d1cfe0017
commit 164cbc9968
16 changed files with 93 additions and 12 deletions
@@ -155,7 +155,6 @@ object AbstractTypeMapper {
typeArgument.isStarProjection() -> Variance.OUT_VARIANCE to nullableAnyType()
else -> typeArgument.getVariance().toVariance() to typeArgument.getType()
}
require(memberType is SimpleTypeMarker)
val arrayElementType: Type
sw?.writeArrayType()
@@ -202,4 +201,14 @@ object AbstractTypeMapper {
TypeVariance.OUT -> Variance.OUT_VARIANCE
TypeVariance.INV -> Variance.INVARIANT
}
fun <Writer : JvmDescriptorTypeWriter<Type>> isPrimitiveBacked(
context: TypeMappingContext<Writer>,
type: KotlinTypeMarker
): Boolean = context.typeContext.isPrimitiveBacked(type)
private fun TypeSystemCommonBackendContext.isPrimitiveBacked(type: KotlinTypeMarker): Boolean =
!type.isNullableType() &&
(type is SimpleTypeMarker && type.isPrimitiveType() ||
type.typeConstructor().getValueClassProperties()?.singleOrNull()?.let { isPrimitiveBacked(it.second) } == true)
}
@@ -65,6 +65,9 @@ class FirJvmTypeMapper(val session: FirSession) : FirSessionComponent {
return AbstractTypeMapper.mapType(context, type, mode, sw)
}
fun isPrimitiveBacked(type: ConeKotlinType): Boolean =
AbstractTypeMapper.isPrimitiveBacked(defaultContext, type)
private val defaultContext = Context { null }
val typeContext: TypeSystemCommonBackendContext
get() = defaultContext.typeContext
@@ -0,0 +1,4 @@
public final class ImplicitArrayWithFlexibleParameterTypesKt /* ImplicitArrayWithFlexibleParameterTypesKt*/ {
@org.jetbrains.annotations.NotNull()
public static final java.lang.Integer[] getArrayOfFlexibleInts();// getArrayOfFlexibleInts()
}
@@ -0,0 +1,16 @@
// ImplicitArrayWithFlexibleParameterTypesKt
// WITH_STDLIB
// FILE: ImplicitArrayWithFlexibleParameterTypes.kt
fun getArrayOfFlexibleInts() /* : Array<Int!> */ = arrayOf(JavaClass.getJavaInt())
// FILE: JavaClass.java
public class JavaClass {
public static Integer getJavaInt() {
return 10;
}
}
// FIR_COMPARISON
@@ -475,6 +475,11 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/nullabilityAnnotations/Generic.kt");
}
@TestMetadata("ImplicitArrayWithFlexibleParameterTypes.kt")
public void testImplicitArrayWithFlexibleParameterTypes() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/nullabilityAnnotations/ImplicitArrayWithFlexibleParameterTypes.kt");
}
@TestMetadata("IntOverridesAny.kt")
public void testIntOverridesAny() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/nullabilityAnnotations/IntOverridesAny.kt");