KT-56840 [SLC] Don't mark primitive-backed types with @NotNull
This commit is contained in:
committed by
Space Team
parent
bcb517d66b
commit
d81170fbcc
+11
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
public abstract class KtTypeInfoProvider : KtAnalysisSessionComponent() {
|
||||
public abstract fun isFunctionalInterfaceType(type: KtType): Boolean
|
||||
@@ -143,6 +144,16 @@ public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
|
||||
return this.classId in DefaultTypeClassIds.PRIMITIVES
|
||||
}
|
||||
|
||||
context(KtJvmTypeMapperMixIn)
|
||||
public val KtType.isPrimitiveBacked: Boolean
|
||||
get() = withValidityAssertion {
|
||||
if (this !is KtNonErrorClassType) return false
|
||||
return when (this.mapTypeToJvmType().sort) {
|
||||
Type.BOOLEAN, Type.CHAR, Type.BYTE, Type.SHORT, Type.INT, Type.FLOAT, Type.LONG, Type.DOUBLE -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
public val KtType.defaultInitializer: String?
|
||||
get() = withValidityAssertion {
|
||||
when {
|
||||
|
||||
+1
-1
@@ -188,7 +188,7 @@ internal class SymbolLightFieldForProperty private constructor(
|
||||
// NB: not as?, since _initializerValue already checks that
|
||||
(propertySymbol as KtKotlinPropertySymbol).isConst &&
|
||||
// javac rejects all non-primitive and non String constants
|
||||
(propertySymbol.returnType.isPrimitive || propertySymbol.returnType.isString)
|
||||
(propertySymbol.returnType.isPrimitiveBacked || propertySymbol.returnType.isString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-13
@@ -126,28 +126,18 @@ internal fun KtAnalysisSession.getTypeNullability(ktType: KtType): NullabilityTy
|
||||
|
||||
if (ktType.isUnit) return NullabilityType.NotNull
|
||||
|
||||
if (ktType.isPrimitiveBacked) return NullabilityType.Unknown
|
||||
|
||||
if (ktType is KtTypeParameterType) {
|
||||
if (ktType.isMarkedNullable) return NullabilityType.Nullable
|
||||
val subtypeOfNullableSuperType = ktType.symbol.upperBounds.all { upperBound -> upperBound.canBeNull }
|
||||
return if (!subtypeOfNullableSuperType) NullabilityType.NotNull else NullabilityType.Unknown
|
||||
}
|
||||
if (ktType !is KtClassType) return NullabilityType.NotNull
|
||||
|
||||
if (!ktType.isPrimitive) {
|
||||
return ktType.nullabilityType
|
||||
}
|
||||
|
||||
if (ktType !is KtNonErrorClassType) return NullabilityType.NotNull
|
||||
if (ktType.ownTypeArguments.any { it.type is KtClassErrorType }) return NullabilityType.NotNull
|
||||
if (ktType.classId.shortClassName.asString() == SpecialNames.ANONYMOUS_STRING) return NullabilityType.NotNull
|
||||
|
||||
val canonicalSignature = ktType.mapTypeToJvmType().descriptor
|
||||
|
||||
if (canonicalSignature == "[L<error>;") return NullabilityType.NotNull
|
||||
|
||||
val isNotPrimitiveType = canonicalSignature.startsWith("L") || canonicalSignature.startsWith("[")
|
||||
|
||||
return if (isNotPrimitiveType) NullabilityType.NotNull else NullabilityType.Unknown
|
||||
return ktType.nullabilityType
|
||||
}
|
||||
|
||||
internal val KtType.isUnit get() = isClassTypeWithClassId(DefaultTypeClassIds.UNIT)
|
||||
|
||||
+6
@@ -483,6 +483,12 @@ public class SymbolLightClassesByFqNameForLibraryTestGenerated extends AbstractS
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/nullabilityAnnotations/PlatformTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("PrimitiveBackedInlineClasses.kt")
|
||||
public void testPrimitiveBackedInlineClasses() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/nullabilityAnnotations/PrimitiveBackedInlineClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("Primitives.kt")
|
||||
public void testPrimitives() throws Exception {
|
||||
|
||||
+6
@@ -483,6 +483,12 @@ public class SymbolLightClassesParentingForLibraryTestGenerated extends Abstract
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/nullabilityAnnotations/PlatformTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("PrimitiveBackedInlineClasses.kt")
|
||||
public void testPrimitiveBackedInlineClasses() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/nullabilityAnnotations/PrimitiveBackedInlineClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("Primitives.kt")
|
||||
public void testPrimitives() throws Exception {
|
||||
|
||||
+6
@@ -625,6 +625,12 @@ public class SymbolLightClassesByFqNameForSourceTestGenerated extends AbstractSy
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/nullabilityAnnotations/PlatformTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("PrimitiveBackedInlineClasses.kt")
|
||||
public void testPrimitiveBackedInlineClasses() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/nullabilityAnnotations/PrimitiveBackedInlineClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("Primitives.kt")
|
||||
public void testPrimitives() throws Exception {
|
||||
|
||||
+6
@@ -625,6 +625,12 @@ public class SymbolLightClassesParentingForSourceTestGenerated extends AbstractS
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/nullabilityAnnotations/PlatformTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("PrimitiveBackedInlineClasses.kt")
|
||||
public void testPrimitiveBackedInlineClasses() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/nullabilityAnnotations/PrimitiveBackedInlineClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("Primitives.kt")
|
||||
public void testPrimitives() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user