[FIR] Fix determining nullability of type variables and type parameters
This commit is contained in:
committed by
TeamCityServer
parent
e00ff5c473
commit
054c278c83
@@ -17,7 +17,7 @@ fun ConeClassifierLookupTag.toSymbol(useSiteSession: FirSession): FirClassifierS
|
||||
when (this) {
|
||||
is ConeClassLikeLookupTag -> toSymbol(useSiteSession)
|
||||
is ConeClassifierLookupTagWithFixedSymbol -> this.symbol
|
||||
else -> error("Unknown lookupTag type: ${this::class}")
|
||||
else -> null
|
||||
}
|
||||
|
||||
@OptIn(LookupTagInternals::class)
|
||||
|
||||
@@ -394,17 +394,24 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
if (this.isMarkedNullable)
|
||||
return true
|
||||
|
||||
if (this is ConeFlexibleType && this.upperBound.isNullableType())
|
||||
return true
|
||||
|
||||
if (this is ConeTypeParameterType /* || is TypeVariable */)
|
||||
return hasNullableSuperType(type)
|
||||
|
||||
if (this is ConeIntersectionType && intersectedTypes.any { it.isNullableType() }) {
|
||||
return true
|
||||
return when (this) {
|
||||
is ConeFlexibleType -> this.upperBound.isNullableType()
|
||||
is ConeTypeParameterType -> lookupTag.symbol.allBoundsAreNullable()
|
||||
is ConeTypeVariableType -> {
|
||||
val symbol = lookupTag.toSymbol(session) ?: return false
|
||||
when (symbol) {
|
||||
is FirClassSymbol -> false
|
||||
is FirTypeAliasSymbol -> symbol.fir.expandedConeType?.isNullableType() ?: false
|
||||
is FirTypeParameterSymbol -> symbol.allBoundsAreNullable()
|
||||
}
|
||||
}
|
||||
is ConeIntersectionType -> intersectedTypes.all { it.isNullableType() }
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
private fun FirTypeParameterSymbol.allBoundsAreNullable(): Boolean {
|
||||
return fir.bounds.all { it.coneType.isMarkedNullable }
|
||||
}
|
||||
|
||||
private fun TypeConstructorMarker.toFirRegularClass(): FirRegularClass? {
|
||||
|
||||
@@ -93,22 +93,6 @@ fun <T : ConeKotlinType> T.withAttributes(attributes: ConeAttributes): T {
|
||||
} as T
|
||||
}
|
||||
|
||||
fun ConeTypeContext.hasNullableSuperType(type: ConeKotlinType): Boolean {
|
||||
if (type is ConeClassLikeType) return false
|
||||
|
||||
if (type !is ConeLookupTagBasedType) return false // TODO?
|
||||
val symbol = type.lookupTag
|
||||
for (superType in symbol.supertypes()) {
|
||||
if (superType.isNullableType()) return true
|
||||
}
|
||||
//
|
||||
// for (KotlinType supertype : getImmediateSupertypes(type)) {
|
||||
// if (isNullableType(supertype)) return true;
|
||||
// }
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
fun <T : ConeKotlinType> T.withNullability(
|
||||
nullability: ConeNullability,
|
||||
typeContext: ConeInferenceContext? = null,
|
||||
|
||||
Reference in New Issue
Block a user