Approximate definitely not-null types for type parameter's types if they are already not-null (has not-null upper bounds)

^KT-44440 Fixed
This commit is contained in:
Victor Petukhov
2021-01-21 14:57:28 +03:00
parent f2c1608c2b
commit f06a5321a6
12 changed files with 144 additions and 45 deletions
@@ -338,6 +338,12 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon
val originalType = type.original()
val approximatedOriginalType =
if (toSuper) approximateToSuperType(originalType, conf, depth) else approximateToSubType(originalType, conf, depth)
val typeWithErasedNullability = originalType.withNullability(false)
// Approximate T!! into T if T is already not-null (has not-null upper bounds)
if (originalType.typeConstructor().isTypeParameterTypeConstructor() && !typeWithErasedNullability.isNullableType()) {
return typeWithErasedNullability
}
return if (conf.definitelyNotNullType) {
approximatedOriginalType?.makeDefinitelyNotNullOrNotNull()