Mark projection of a nullable captured type as not null during simplification constrains with it and a nullable type variable

^KT-41913 Fixed
This commit is contained in:
Victor Petukhov
2020-09-18 10:25:27 +03:00
parent 0f868ff83f
commit bfb46befa5
6 changed files with 79 additions and 7 deletions
@@ -209,20 +209,16 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck
if (typeVariable.isMarkedNullable()) {
val typeVariableTypeConstructor = typeVariable.typeConstructor()
val subTypeConstructor = subType.typeConstructor()
if (
val resultType = if (
!subTypeConstructor.isTypeVariable() &&
typeVariableTypeConstructor.isTypeVariable() &&
(typeVariableTypeConstructor as TypeVariableTypeConstructorMarker).isContainedInInvariantOrContravariantPositions()
) {
if (subType.isCapturedType()) {
(subType as CapturedTypeMarker).withNotNullProjection()
} else {
subType.withNullability(false)
}
subType.withNullability(false)
} else {
subType.makeDefinitelyNotNullOrNotNull()
}
if (resultType is CapturedTypeMarker) resultType.withNotNullProjection() else resultType
} else subType
is FlexibleTypeMarker -> {