[FIR, IR] AbstractExpectActualChecker: drop redundant code
- getCallablesStrongIncompatibility is unused (because it moved to the "matcher" KT-62590) - `checkClassScopesCompatibility` parameter is always `true` or unused Review: https://jetbrains.team/p/kt/reviews/12750/timeline
This commit is contained in:
-1
@@ -83,7 +83,6 @@ internal object FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker : Fir
|
|||||||
): FirNamedFunctionSymbol? {
|
): FirNamedFunctionSymbol? {
|
||||||
val potentialExpects = findPotentialExpectClassMembersForActual(
|
val potentialExpects = findPotentialExpectClassMembersForActual(
|
||||||
expectSymbol, actualSymbol, actualMember,
|
expectSymbol, actualSymbol, actualMember,
|
||||||
checkClassScopesCompatibility = false
|
|
||||||
)
|
)
|
||||||
val expectMember: DeclarationSymbolMarker = potentialExpects.entries
|
val expectMember: DeclarationSymbolMarker = potentialExpects.entries
|
||||||
.singleOrNull { it.value == ExpectActualMatchingCompatibility.MatchedSuccessfully }?.key
|
.singleOrNull { it.value == ExpectActualMatchingCompatibility.MatchedSuccessfully }?.key
|
||||||
|
|||||||
-1
@@ -242,7 +242,6 @@ object FirExpectActualDeclarationChecker : FirBasicDeclarationChecker() {
|
|||||||
AbstractExpectActualChecker.getClassifiersCompatibility(
|
AbstractExpectActualChecker.getClassifiersCompatibility(
|
||||||
expectSymbol,
|
expectSymbol,
|
||||||
actualSymbol,
|
actualSymbol,
|
||||||
checkClassScopesCompatibility = true,
|
|
||||||
context,
|
context,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -523,7 +523,6 @@ class FirExpectActualMatchingContextImpl private constructor(
|
|||||||
expectClass: RegularClassSymbolMarker,
|
expectClass: RegularClassSymbolMarker,
|
||||||
actualClass: RegularClassSymbolMarker,
|
actualClass: RegularClassSymbolMarker,
|
||||||
actualMember: DeclarationSymbolMarker,
|
actualMember: DeclarationSymbolMarker,
|
||||||
checkClassScopesCompatibility: Boolean,
|
|
||||||
): Map<FirBasedSymbol<*>, ExpectActualMatchingCompatibility> {
|
): Map<FirBasedSymbol<*>, ExpectActualMatchingCompatibility> {
|
||||||
val mapping = actualClass.asSymbol().fir.memberExpectForActual
|
val mapping = actualClass.asSymbol().fir.memberExpectForActual
|
||||||
return mapping?.get(actualMember to expectClass) ?: emptyMap()
|
return mapping?.get(actualMember to expectClass) ?: emptyMap()
|
||||||
|
|||||||
-1
@@ -234,7 +234,6 @@ private class ExpectActualLinkCollector : IrElementVisitor<Unit, ExpectActualLin
|
|||||||
expectSymbol,
|
expectSymbol,
|
||||||
listOf(matched),
|
listOf(matched),
|
||||||
context,
|
context,
|
||||||
checkClassScopesCompatibility = true,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -557,7 +557,6 @@ internal abstract class IrExpectActualMatchingContext(
|
|||||||
expectClass: RegularClassSymbolMarker,
|
expectClass: RegularClassSymbolMarker,
|
||||||
actualClass: RegularClassSymbolMarker,
|
actualClass: RegularClassSymbolMarker,
|
||||||
actualMember: DeclarationSymbolMarker,
|
actualMember: DeclarationSymbolMarker,
|
||||||
checkClassScopesCompatibility: Boolean,
|
|
||||||
): Map<out DeclarationSymbolMarker, ExpectActualMatchingCompatibility> = error("Should not be called")
|
): Map<out DeclarationSymbolMarker, ExpectActualMatchingCompatibility> = error("Should not be called")
|
||||||
|
|
||||||
// It's a stub, because not needed anywhere
|
// It's a stub, because not needed anywhere
|
||||||
|
|||||||
-5
@@ -310,11 +310,6 @@ object AbstractExpectActualAnnotationMatchChecker {
|
|||||||
}
|
}
|
||||||
val expectToCompatibilityMap = findPotentialExpectClassMembersForActual(
|
val expectToCompatibilityMap = findPotentialExpectClassMembersForActual(
|
||||||
expectClass, actualClass, actualMember,
|
expectClass, actualClass, actualMember,
|
||||||
// Optimization: don't check class scopes, because:
|
|
||||||
// 1. Annotation checker runs no matter if found expect class is compatible or not.
|
|
||||||
// 2. Class always has at most one corresponding `expect` class (unlike for functions, which may have several overrides),
|
|
||||||
// so we are sure that we found the right member.
|
|
||||||
checkClassScopesCompatibility = false,
|
|
||||||
)
|
)
|
||||||
val expectMember = expectToCompatibilityMap
|
val expectMember = expectToCompatibilityMap
|
||||||
.filter { it.value == ExpectActualMatchingCompatibility.MatchedSuccessfully }.keys.singleOrNull()
|
.filter { it.value == ExpectActualMatchingCompatibility.MatchedSuccessfully }.keys.singleOrNull()
|
||||||
|
|||||||
+1
-90
@@ -33,7 +33,6 @@ object AbstractExpectActualChecker {
|
|||||||
fun <T : DeclarationSymbolMarker> getClassifiersCompatibility(
|
fun <T : DeclarationSymbolMarker> getClassifiersCompatibility(
|
||||||
expectClassSymbol: RegularClassSymbolMarker,
|
expectClassSymbol: RegularClassSymbolMarker,
|
||||||
actualClassLikeSymbol: ClassLikeSymbolMarker,
|
actualClassLikeSymbol: ClassLikeSymbolMarker,
|
||||||
checkClassScopesCompatibility: Boolean,
|
|
||||||
context: ExpectActualMatchingContext<T>,
|
context: ExpectActualMatchingContext<T>,
|
||||||
): ExpectActualCheckingCompatibility<T> {
|
): ExpectActualCheckingCompatibility<T> {
|
||||||
val result = with(context) {
|
val result = with(context) {
|
||||||
@@ -41,7 +40,6 @@ object AbstractExpectActualChecker {
|
|||||||
expectClassSymbol,
|
expectClassSymbol,
|
||||||
actualClassLikeSymbol,
|
actualClassLikeSymbol,
|
||||||
parentSubstitutor = null,
|
parentSubstitutor = null,
|
||||||
checkClassScopesCompatibility,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@@ -74,7 +72,6 @@ object AbstractExpectActualChecker {
|
|||||||
expectDeclaration: DeclarationSymbolMarker,
|
expectDeclaration: DeclarationSymbolMarker,
|
||||||
actualDeclarations: List<DeclarationSymbolMarker>,
|
actualDeclarations: List<DeclarationSymbolMarker>,
|
||||||
context: ExpectActualMatchingContext<T>,
|
context: ExpectActualMatchingContext<T>,
|
||||||
checkClassScopesCompatibility: Boolean,
|
|
||||||
) {
|
) {
|
||||||
with(context) {
|
with(context) {
|
||||||
checkSingleExpectAgainstPotentialActuals(
|
checkSingleExpectAgainstPotentialActuals(
|
||||||
@@ -84,7 +81,6 @@ object AbstractExpectActualChecker {
|
|||||||
expectClassSymbol = null,
|
expectClassSymbol = null,
|
||||||
actualClassSymbol = null,
|
actualClassSymbol = null,
|
||||||
incompatibleMembers = null,
|
incompatibleMembers = null,
|
||||||
checkClassScopesCompatibility = checkClassScopesCompatibility,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,12 +91,10 @@ object AbstractExpectActualChecker {
|
|||||||
expectClassSymbol: RegularClassSymbolMarker,
|
expectClassSymbol: RegularClassSymbolMarker,
|
||||||
actualClassLikeSymbol: ClassLikeSymbolMarker,
|
actualClassLikeSymbol: ClassLikeSymbolMarker,
|
||||||
parentSubstitutor: TypeSubstitutorMarker?,
|
parentSubstitutor: TypeSubstitutorMarker?,
|
||||||
checkClassScopes: Boolean,
|
|
||||||
): ExpectActualCheckingCompatibility<*> = getClassifiersIncompatibility(
|
): ExpectActualCheckingCompatibility<*> = getClassifiersIncompatibility(
|
||||||
expectClassSymbol,
|
expectClassSymbol,
|
||||||
actualClassLikeSymbol,
|
actualClassLikeSymbol,
|
||||||
parentSubstitutor,
|
parentSubstitutor,
|
||||||
checkClassScopes,
|
|
||||||
)
|
)
|
||||||
?: ExpectActualCheckingCompatibility.Compatible
|
?: ExpectActualCheckingCompatibility.Compatible
|
||||||
|
|
||||||
@@ -110,7 +104,6 @@ object AbstractExpectActualChecker {
|
|||||||
expectClassSymbol: RegularClassSymbolMarker,
|
expectClassSymbol: RegularClassSymbolMarker,
|
||||||
actualClassLikeSymbol: ClassLikeSymbolMarker,
|
actualClassLikeSymbol: ClassLikeSymbolMarker,
|
||||||
parentSubstitutor: TypeSubstitutorMarker?,
|
parentSubstitutor: TypeSubstitutorMarker?,
|
||||||
checkClassScopesCompatibility: Boolean,
|
|
||||||
): ExpectActualCheckingCompatibility.Incompatible<*>? {
|
): ExpectActualCheckingCompatibility.Incompatible<*>? {
|
||||||
// Can't check FQ names here because nested expected class may be implemented via actual typealias's expansion with the other FQ name
|
// Can't check FQ names here because nested expected class may be implemented via actual typealias's expansion with the other FQ name
|
||||||
require(expectClassSymbol.name == actualClassLikeSymbol.name) {
|
require(expectClassSymbol.name == actualClassLikeSymbol.name) {
|
||||||
@@ -165,9 +158,7 @@ object AbstractExpectActualChecker {
|
|||||||
return ExpectActualCheckingCompatibility.Supertypes
|
return ExpectActualCheckingCompatibility.Supertypes
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkClassScopesCompatibility) {
|
getClassScopesIncompatibility(expectClassSymbol, actualClass, substitutor)?.let { return it }
|
||||||
getClassScopesIncompatibility(expectClassSymbol, actualClass, substitutor)?.let { return it }
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -256,7 +247,6 @@ object AbstractExpectActualChecker {
|
|||||||
expectClassSymbol,
|
expectClassSymbol,
|
||||||
actualClassSymbol,
|
actualClassSymbol,
|
||||||
incompatibleMembers,
|
incompatibleMembers,
|
||||||
checkClassScopesCompatibility = true,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -284,7 +274,6 @@ object AbstractExpectActualChecker {
|
|||||||
expectClassSymbol: RegularClassSymbolMarker?,
|
expectClassSymbol: RegularClassSymbolMarker?,
|
||||||
actualClassSymbol: RegularClassSymbolMarker?,
|
actualClassSymbol: RegularClassSymbolMarker?,
|
||||||
incompatibleMembers: MutableList<Pair<DeclarationSymbolMarker, Map<ExpectActualCheckingCompatibility.Incompatible<*>, List<DeclarationSymbolMarker?>>>>?,
|
incompatibleMembers: MutableList<Pair<DeclarationSymbolMarker, Map<ExpectActualCheckingCompatibility.Incompatible<*>, List<DeclarationSymbolMarker?>>>>?,
|
||||||
checkClassScopesCompatibility: Boolean,
|
|
||||||
) {
|
) {
|
||||||
val mapping = actualMembers.keysToMap { actualMember ->
|
val mapping = actualMembers.keysToMap { actualMember ->
|
||||||
when (expectMember) {
|
when (expectMember) {
|
||||||
@@ -302,7 +291,6 @@ object AbstractExpectActualChecker {
|
|||||||
expectMember,
|
expectMember,
|
||||||
actualMember as ClassLikeSymbolMarker,
|
actualMember as ClassLikeSymbolMarker,
|
||||||
parentSubstitutor,
|
parentSubstitutor,
|
||||||
checkClassScopesCompatibility,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else -> error("Unsupported declaration: $expectMember ($actualMembers)")
|
else -> error("Unsupported declaration: $expectMember ($actualMembers)")
|
||||||
@@ -360,62 +348,6 @@ object AbstractExpectActualChecker {
|
|||||||
) ?: ExpectActualCheckingCompatibility.Compatible
|
) ?: ExpectActualCheckingCompatibility.Compatible
|
||||||
}
|
}
|
||||||
|
|
||||||
context(ExpectActualMatchingContext<*>)
|
|
||||||
private fun getCallablesStrongIncompatibility(
|
|
||||||
expectDeclaration: CallableSymbolMarker,
|
|
||||||
actualDeclaration: CallableSymbolMarker,
|
|
||||||
insideAnnotationClass: Boolean,
|
|
||||||
parentSubstitutor: TypeSubstitutorMarker?,
|
|
||||||
): ExpectActualMatchingCompatibility.Mismatch? {
|
|
||||||
if (expectDeclaration is FunctionSymbolMarker != actualDeclaration is FunctionSymbolMarker) {
|
|
||||||
return ExpectActualMatchingCompatibility.CallableKind
|
|
||||||
}
|
|
||||||
|
|
||||||
val expectedReceiverType = expectDeclaration.extensionReceiverType
|
|
||||||
val actualReceiverType = actualDeclaration.extensionReceiverType
|
|
||||||
if ((expectedReceiverType != null) != (actualReceiverType != null)) {
|
|
||||||
return ExpectActualMatchingCompatibility.ParameterShape
|
|
||||||
}
|
|
||||||
|
|
||||||
val expectedValueParameters = expectDeclaration.valueParameters
|
|
||||||
val actualValueParameters = actualDeclaration.valueParameters
|
|
||||||
if (!valueParametersCountCompatible(expectDeclaration, actualDeclaration, expectedValueParameters, actualValueParameters)) {
|
|
||||||
return ExpectActualMatchingCompatibility.ParameterCount
|
|
||||||
}
|
|
||||||
|
|
||||||
val expectedTypeParameters = expectDeclaration.typeParameters
|
|
||||||
val actualTypeParameters = actualDeclaration.typeParameters
|
|
||||||
if (expectedTypeParameters.size != actualTypeParameters.size) {
|
|
||||||
return ExpectActualMatchingCompatibility.FunctionTypeParameterCount
|
|
||||||
}
|
|
||||||
|
|
||||||
val substitutor = createExpectActualTypeParameterSubstitutor(
|
|
||||||
(expectedTypeParameters zipIfSizesAreEqual actualTypeParameters)
|
|
||||||
?: error("expect/actual type parameters sizes are checked earlier"),
|
|
||||||
parentSubstitutor
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
|
||||||
!areCompatibleTypeLists(
|
|
||||||
expectedValueParameters.toTypeList(substitutor),
|
|
||||||
actualValueParameters.toTypeList(createEmptySubstitutor()),
|
|
||||||
insideAnnotationClass
|
|
||||||
) || !areCompatibleExpectActualTypes(
|
|
||||||
expectedReceiverType?.let { substitutor.safeSubstitute(it) },
|
|
||||||
actualReceiverType,
|
|
||||||
parameterOfAnnotationComparisonMode = false
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return ExpectActualMatchingCompatibility.ParameterTypes
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!areCompatibleTypeParameterUpperBounds(expectedTypeParameters, actualTypeParameters, substitutor)) {
|
|
||||||
return ExpectActualMatchingCompatibility.FunctionTypeParameterUpperBounds
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
context(ExpectActualMatchingContext<*>)
|
context(ExpectActualMatchingContext<*>)
|
||||||
private fun getCallablesCheckingIncompatibility(
|
private fun getCallablesCheckingIncompatibility(
|
||||||
expectDeclaration: CallableSymbolMarker,
|
expectDeclaration: CallableSymbolMarker,
|
||||||
@@ -521,22 +453,6 @@ object AbstractExpectActualChecker {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
context(ExpectActualMatchingContext<*>)
|
|
||||||
private fun valueParametersCountCompatible(
|
|
||||||
expectDeclaration: CallableSymbolMarker,
|
|
||||||
actualDeclaration: CallableSymbolMarker,
|
|
||||||
expectValueParameters: List<ValueParameterSymbolMarker>,
|
|
||||||
actualValueParameters: List<ValueParameterSymbolMarker>,
|
|
||||||
): Boolean {
|
|
||||||
if (expectValueParameters.size == actualValueParameters.size) return true
|
|
||||||
|
|
||||||
return if (expectDeclaration.isAnnotationConstructor() && actualDeclaration.isAnnotationConstructor()) {
|
|
||||||
expectValueParameters.isEmpty() && actualValueParameters.all { it.hasDefaultValue }
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
context(ExpectActualMatchingContext<*>)
|
context(ExpectActualMatchingContext<*>)
|
||||||
private fun areCompatibleTypeLists(
|
private fun areCompatibleTypeLists(
|
||||||
expectedTypes: List<KotlinTypeMarker?>,
|
expectedTypes: List<KotlinTypeMarker?>,
|
||||||
@@ -720,11 +636,6 @@ object AbstractExpectActualChecker {
|
|||||||
|
|
||||||
// ---------------------------------------- Utils ----------------------------------------
|
// ---------------------------------------- Utils ----------------------------------------
|
||||||
|
|
||||||
context(ExpectActualMatchingContext<*>)
|
|
||||||
private fun List<ValueParameterSymbolMarker>.toTypeList(substitutor: TypeSubstitutorMarker): List<KotlinTypeMarker> {
|
|
||||||
return this.map { substitutor.safeSubstitute(it.returnType) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline fun <T, K> equalsBy(first: List<T>, second: List<T>, selector: (T) -> K): Boolean {
|
private inline fun <T, K> equalsBy(first: List<T>, second: List<T>, selector: (T) -> K): Boolean {
|
||||||
for (i in first.indices) {
|
for (i in first.indices) {
|
||||||
if (selector(first[i]) != selector(second[i])) return false
|
if (selector(first[i]) != selector(second[i])) return false
|
||||||
|
|||||||
-1
@@ -224,7 +224,6 @@ interface ExpectActualMatchingContext<T : DeclarationSymbolMarker> : TypeSystemC
|
|||||||
expectClass: RegularClassSymbolMarker,
|
expectClass: RegularClassSymbolMarker,
|
||||||
actualClass: RegularClassSymbolMarker,
|
actualClass: RegularClassSymbolMarker,
|
||||||
actualMember: DeclarationSymbolMarker,
|
actualMember: DeclarationSymbolMarker,
|
||||||
checkClassScopesCompatibility: Boolean,
|
|
||||||
): Map<out DeclarationSymbolMarker, ExpectActualMatchingCompatibility>
|
): Map<out DeclarationSymbolMarker, ExpectActualMatchingCompatibility>
|
||||||
|
|
||||||
fun DeclarationSymbolMarker.getSourceElement(): SourceElementMarker
|
fun DeclarationSymbolMarker.getSourceElement(): SourceElementMarker
|
||||||
|
|||||||
Reference in New Issue
Block a user