[FIR] Fix nullability of types produced by ConeRawScopeSubstitutor

#KT-66067 Fixed
This commit is contained in:
Kirill Rakhman
2024-02-28 14:52:06 +01:00
committed by Space Team
parent b6a6b12f0f
commit 5bca945d05
25 changed files with 369 additions and 5 deletions
@@ -281,7 +281,7 @@ class ConeRawScopeSubstitutor(
return when {
type is ConeTypeParameterType -> {
substituteOrSelf(
listOf(type.lookupTag.symbol).getProjectionsForRawType(useSiteSession)[0] as ConeKotlinType
listOf(type.lookupTag.symbol).getProjectionsForRawType(useSiteSession, makeNullable = type.isNullable)[0]
)
}
type is ConeClassLikeType && type.typeArguments.isNotEmpty() -> {
@@ -296,7 +296,7 @@ class ConeRawScopeSubstitutor(
val firClass = type.fullyExpandedType(useSiteSession).lookupTag.toFirRegularClassSymbol(useSiteSession) ?: return null
ConeRawType.create(
type.withArguments(firClass.typeParameterSymbols.getProjectionsForRawType(useSiteSession)),
type.withArguments(firClass.typeParameterSymbols.getProjectionsForRawType(useSiteSession, makeNullable = type.isNullable)),
type.replaceArgumentsWithStarProjections()
)
}
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.fir.utils.exceptions.withConeTypeEntry
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.utils.addToStdlib.applyIf
import org.jetbrains.kotlin.utils.addToStdlib.butIf
import org.jetbrains.kotlin.utils.addToStdlib.runIf
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
@@ -688,12 +689,12 @@ fun List<FirTypeParameterSymbol>.eraseToUpperBoundsAssociated(
}
}
fun List<FirTypeParameterSymbol>.getProjectionsForRawType(session: FirSession): Array<ConeTypeProjection> {
fun List<FirTypeParameterSymbol>.getProjectionsForRawType(session: FirSession, makeNullable: Boolean): Array<ConeKotlinType> {
val cache = mutableMapOf<FirTypeParameter, ConeKotlinType>()
return Array(size) { index ->
this[index].fir.eraseToUpperBound(
session, cache, mode = EraseUpperBoundMode.FOR_RAW_TYPE_ERASURE
)
).applyIf(makeNullable) { withNullability(ConeNullability.NULLABLE, session.typeContext) }
}
}