FE: do not enhance ? in jspecify NullMarked scope

No clue whether this should be done for `@TypeQualifierDefault` since it
appears to have no specification whatsoever.

 #KT-48262 Fixed
This commit is contained in:
pyos
2021-08-16 18:41:45 +02:00
committed by Victor Petukhov
parent 5819959cce
commit 47d0211370
7 changed files with 23 additions and 89 deletions
@@ -317,6 +317,12 @@ class SignatureEnhancement(
typeParameterForArgument: TypeParameterDescriptor?,
isFromStarProjection: Boolean
): JavaTypeQualifiers {
if (isFromStarProjection && typeParameterForArgument?.variance == Variance.IN_VARIANCE) {
// Star projections can only be enhanced in one way: `?` -> `? extends <something>`. Given a Kotlin type `C<in T>
// (declaration-site variance), this is not a valid enhancement due to conflicting variances.
return JavaTypeQualifiers.NONE
}
val areImprovementsInStrictMode = containerContext.components.settings.typeEnhancementImprovementsInStrictMode
val composedAnnotation =
@@ -349,7 +355,7 @@ class SignatureEnhancement(
containerContext.defaultTypeQualifiers?.get(containerApplicabilityType)
else
defaultQualifiersForType)?.takeIf {
it.affectsTypeParameterBasedTypes || !isTypeParameter()
(it.affectsTypeParameterBasedTypes || !isTypeParameter()) && (it.affectsStarProjection || !isFromStarProjection)
}
val (nullabilityFromBoundsForTypeBasedOnTypeParameter, isTypeParameterWithNotNullableBounds) =
@@ -362,8 +368,7 @@ class SignatureEnhancement(
?: computeNullabilityInfoInTheAbsenceOfExplicitAnnotation(
nullabilityFromBoundsForTypeBasedOnTypeParameter,
defaultTypeQualifier,
typeParameterForArgument,
isFromStarProjection
typeParameterForArgument
)
val isNotNullTypeParameter =
@@ -390,8 +395,7 @@ class SignatureEnhancement(
private fun computeNullabilityInfoInTheAbsenceOfExplicitAnnotation(
nullabilityFromBoundsForTypeBasedOnTypeParameter: NullabilityQualifierWithMigrationStatus?,
defaultTypeQualifier: JavaDefaultQualifiers?,
typeParameterForArgument: TypeParameterDescriptor?,
isFromStarProjection: Boolean
typeParameterForArgument: TypeParameterDescriptor?
): NullabilityQualifierWithMigrationStatus? {
val result =
@@ -412,7 +416,7 @@ class SignatureEnhancement(
)
}
if (result == null || isFromStarProjection) return boundsFromTypeParameterForArgument
if (result == null) return boundsFromTypeParameterForArgument
return mostSpecific(boundsFromTypeParameterForArgument, result)
}