[FIR] Implement canBeNull for captured type by checking its supertypes

#KT-62959
This commit is contained in:
Kirill Rakhman
2024-01-04 10:36:55 +01:00
committed by Space Team
parent 7b0c4e5bf6
commit 00491a78f1
2 changed files with 4 additions and 0 deletions
@@ -256,6 +256,9 @@ class Fir2IrImplicitCastInserter(
}
private fun ConeKotlinType.acceptsNullValues(): Boolean {
if (this is ConeCapturedType && this.constructor.projection.kind == ProjectionKind.IN) {
return constructor.projection.type!!.canBeNull(session)
}
return canBeNull(session) || hasEnhancedNullability
}
@@ -821,6 +821,7 @@ fun ConeKotlinType.canBeNull(session: FirSession): Boolean {
it.coneType.fullyExpandedType(session).canBeNull(session)
}
is ConeIntersectionType -> intersectedTypes.all { it.canBeNull(session) }
is ConeCapturedType -> constructor.supertypes?.all { it.canBeNull(session) } == true
else -> fullyExpandedType(session).isNullable
}
}