[FIR] Remove redundant special cases from FirStandardOverrideChecker

AbstractTypeChecker.equalTypes already handles the same special cases.
This commit is contained in:
Kirill Rakhman
2023-11-20 11:54:07 +01:00
committed by Space Team
parent 4882ac6599
commit ad3da48f55
@@ -15,39 +15,14 @@ import org.jetbrains.kotlin.fir.resolve.transformers.ensureResolvedTypeDeclarati
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
class FirStandardOverrideChecker(private val session: FirSession) : FirAbstractOverrideChecker() {
private val context = session.typeContext
private fun isEqualTypes(substitutedCandidateType: ConeKotlinType, substitutedBaseType: ConeKotlinType): Boolean {
return with(context) {
val baseIsFlexible = substitutedBaseType.isFlexible()
val candidateIsFlexible = substitutedCandidateType.isFlexible()
if (baseIsFlexible == candidateIsFlexible) {
return AbstractTypeChecker.equalTypes(context, substitutedCandidateType, substitutedBaseType)
}
val lowerBound: SimpleTypeMarker
val upperBound: SimpleTypeMarker
val type: KotlinTypeMarker
if (baseIsFlexible) {
lowerBound = substitutedBaseType.lowerBoundIfFlexible()
upperBound = substitutedBaseType.upperBoundIfFlexible()
type = substitutedCandidateType
} else {
lowerBound = substitutedCandidateType.lowerBoundIfFlexible()
upperBound = substitutedCandidateType.upperBoundIfFlexible()
type = substitutedBaseType
}
AbstractTypeChecker.isSubtypeOf(context, lowerBound, type) && AbstractTypeChecker.isSubtypeOf(context, type, upperBound)
}
}
private fun isEqualTypes(candidateType: ConeKotlinType, baseType: ConeKotlinType, substitutor: ConeSubstitutor): Boolean {
val substitutedCandidateType = substitutor.substituteOrSelf(candidateType)
val substitutedBaseType = substitutor.substituteOrSelf(baseType)
return isEqualTypes(substitutedCandidateType, substitutedBaseType)
return AbstractTypeChecker.equalTypes(context, substitutedCandidateType, substitutedBaseType)
}
fun isEqualTypes(candidateTypeRef: FirTypeRef, baseTypeRef: FirTypeRef, substitutor: ConeSubstitutor): Boolean {
@@ -81,9 +56,15 @@ class FirStandardOverrideChecker(private val session: FirSession) : FirAbstractO
val substitutedOverrideType = substitutor.substituteOrSelf(overrideBound.coneType)
val substitutedBaseType = substitutor.substituteOrSelf(baseBound.coneType)
if (isEqualTypes(substitutedOverrideType, substitutedBaseType)) return true
if (AbstractTypeChecker.equalTypes(context, substitutedOverrideType, substitutedBaseType)) return true
return overrideTypeParameter.symbol.resolvedBounds.any { bound -> isEqualTypes(bound.coneType, substitutedBaseType, substitutor) } &&
return overrideTypeParameter.symbol.resolvedBounds.any { bound ->
isEqualTypes(
bound.coneType,
substitutedBaseType,
substitutor
)
} &&
baseTypeParameter.symbol.resolvedBounds.any { bound -> isEqualTypes(bound.coneType, substitutedOverrideType, substitutor) }
}