ConeSimpleKotlinType: introduce & use unwrapDefinitelyNotNull
This commit is contained in:
committed by
TeamCityServer
parent
d1194e5fd2
commit
27d4c745cb
+2
-2
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeCyclicTypeBound
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
object FirCyclicTypeBoundsChecker : FirBasicDeclarationChecker() {
|
||||
|
||||
@@ -77,5 +76,6 @@ object FirCyclicTypeBoundsChecker : FirBasicDeclarationChecker() {
|
||||
private fun extractTypeParamNames(ref: FirTypeRef): Set<Name> =
|
||||
ref.unwrapBound().mapNotNull { extractTypeParamName(it.coneType) }.toSet()
|
||||
|
||||
private fun extractTypeParamName(type: ConeKotlinType): Name? = type.safeAs<ConeTypeParameterType>()?.lookupTag?.name
|
||||
private fun extractTypeParamName(type: ConeKotlinType): Name? =
|
||||
(type.lowerBoundIfFlexible().unwrapDefinitelyNotNull() as? ConeTypeParameterType)?.lookupTag?.name
|
||||
}
|
||||
|
||||
+5
-3
@@ -24,12 +24,14 @@ object FirTopLevelTypeAliasChecker : FirTypeAliasChecker() {
|
||||
}
|
||||
|
||||
fun containsTypeParameter(type: ConeKotlinType): Boolean {
|
||||
if (type is ConeTypeParameterType) {
|
||||
val unwrapped = type.lowerBoundIfFlexible().unwrapDefinitelyNotNull()
|
||||
|
||||
if (unwrapped is ConeTypeParameterType) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (type is ConeClassLikeType && type.lookupTag.toSymbol(context.session) is FirTypeAliasSymbol) {
|
||||
for (typeArgument in type.typeArguments) {
|
||||
if (unwrapped is ConeClassLikeType && unwrapped.lookupTag.toSymbol(context.session) is FirTypeAliasSymbol) {
|
||||
for (typeArgument in unwrapped.typeArguments) {
|
||||
val typeArgumentType = (typeArgument as? ConeKotlinType) ?: (typeArgument as? ConeKotlinTypeProjection)?.type
|
||||
if (typeArgumentType != null && containsTypeParameter(typeArgumentType)) {
|
||||
return true
|
||||
|
||||
@@ -175,6 +175,13 @@ fun ConeKotlinType.lowerBoundIfFlexible(): ConeSimpleKotlinType {
|
||||
}
|
||||
}
|
||||
|
||||
fun ConeSimpleKotlinType.unwrapDefinitelyNotNull(): ConeSimpleKotlinType {
|
||||
return when (this) {
|
||||
is ConeDefinitelyNotNullType -> original
|
||||
else -> this
|
||||
}
|
||||
}
|
||||
|
||||
class ConeCapturedTypeConstructor(
|
||||
val projection: ConeTypeProjection,
|
||||
var supertypes: List<ConeKotlinType>? = null,
|
||||
|
||||
Reference in New Issue
Block a user