[FIR, IR] Cleanups around allRecursivelyOverriddenDeclarationsIncludingSelf
- Pass containingClass (helps to avoid calculations of the containingClass in allRecursivelyOverriddenDeclarationsIncludingSelf implementation) - Reuse allRecursivelyOverriddenDeclarationsIncludingSelf by DefaultArgumentsInExpectActualizedByFakeOverride & ActualFunctionWithDefaultParameters Review: https://jetbrains.team/p/kt/reviews/13244
This commit is contained in:
+4
-5
@@ -259,14 +259,13 @@ class FirExpectActualMatchingContextImpl private constructor(
|
||||
override val CallableSymbolMarker.typeParameters: List<TypeParameterSymbolMarker>
|
||||
get() = asSymbol().typeParameterSymbols
|
||||
|
||||
override fun FunctionSymbolMarker.allRecursivelyOverriddenDeclarationsIncludingSelf(): Sequence<CallableSymbolMarker> {
|
||||
override fun FunctionSymbolMarker.allRecursivelyOverriddenDeclarationsIncludingSelf(containingClass: RegularClassSymbolMarker?): List<CallableSymbolMarker> {
|
||||
return when (val symbol = asSymbol()) {
|
||||
is FirConstructorSymbol, is FirFunctionWithoutNameSymbol -> sequenceOf(this)
|
||||
is FirConstructorSymbol, is FirFunctionWithoutNameSymbol -> listOf(symbol)
|
||||
is FirNamedFunctionSymbol -> {
|
||||
if (containingClass == null) return listOf(symbol)
|
||||
val session = symbol.moduleData.session
|
||||
val containingClass = symbol.containingClassLookupTag()?.toFirRegularClassSymbol(session)
|
||||
?: return sequenceOf(symbol)
|
||||
(sequenceOf(symbol) + symbol.overriddenFunctions(containingClass, session, actualScopeSession).asSequence())
|
||||
(listOf(symbol) + symbol.overriddenFunctions(containingClass.asSymbol(), session, actualScopeSession).asSequence())
|
||||
// Tests work even if you don't filter out fake-overrides. Filtering fake-overrides is needed because
|
||||
// the returned descriptors are compared by `equals`. And `equals` for fake-overrides is weird.
|
||||
// I didn't manage to invent a test that would check this condition
|
||||
|
||||
+3
-3
@@ -298,10 +298,10 @@ internal abstract class IrExpectActualMatchingContext(
|
||||
onEnumEntry = { emptyList() }
|
||||
)
|
||||
|
||||
override fun FunctionSymbolMarker.allRecursivelyOverriddenDeclarationsIncludingSelf(): Sequence<CallableSymbolMarker> =
|
||||
override fun FunctionSymbolMarker.allRecursivelyOverriddenDeclarationsIncludingSelf(containingClass: RegularClassSymbolMarker?): List<CallableSymbolMarker> =
|
||||
when (val node = asIr()) {
|
||||
is IrConstructor -> sequenceOf(this)
|
||||
is IrSimpleFunction -> (sequenceOf(this) + node.overriddenSymbols)
|
||||
is IrConstructor -> listOf(this)
|
||||
is IrSimpleFunction -> (listOf(this) + node.overriddenSymbols)
|
||||
// Tests work even if you don't filter out fake-overrides. Filtering fake-overrides is needed because
|
||||
// the returned descriptors are compared by `equals`. And `equals` for fake-overrides is weird.
|
||||
// I didn't manage to invent a test that would check this condition
|
||||
|
||||
+7
-6
@@ -373,13 +373,16 @@ object AbstractExpectActualChecker {
|
||||
// "parameters" checks are required only for functions, because only functions can have parameters
|
||||
actualDeclaration is FunctionSymbolMarker && expectDeclaration is FunctionSymbolMarker
|
||||
) {
|
||||
val expectOverriddenDeclarations =
|
||||
expectDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf(expectContainingClass).toSet()
|
||||
val actualOverriddenDeclarations =
|
||||
actualDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf(actualContainingClass).toSet()
|
||||
if (languageVersionSettings.supportsFeature(LanguageFeature.ProhibitDefaultArgumentsInExpectActualizedByFakeOverride) &&
|
||||
(actualDeclaration.isFakeOverride(actualContainingClass) || actualDeclaration.isDelegatedMember) &&
|
||||
// If default params came from common supertypes of actual class and expect class then it's a valid code.
|
||||
// Here we filter out such default params.
|
||||
(expectDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf() -
|
||||
actualDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf().toSet())
|
||||
.flatMap { it.valueParameters }.any { it.hasDefaultValueNonRecursive }
|
||||
(expectOverriddenDeclarations - actualOverriddenDeclarations).flatMap { it.valueParameters }
|
||||
.any { it.hasDefaultValueNonRecursive }
|
||||
) {
|
||||
return ExpectActualCheckingCompatibility.DefaultArgumentsInExpectActualizedByFakeOverride
|
||||
}
|
||||
@@ -389,9 +392,7 @@ object AbstractExpectActualChecker {
|
||||
if (!actualDeclaration.isAnnotationConstructor() &&
|
||||
// If default params came from common supertypes of actual class and expect class then it's a valid code.
|
||||
// Here we filter out such default params.
|
||||
(actualDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf() -
|
||||
expectDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf().toSet())
|
||||
.flatMap { it.valueParameters }.any { it.hasDefaultValue }
|
||||
(actualOverriddenDeclarations - expectOverriddenDeclarations).flatMap { it.valueParameters }.any { it.hasDefaultValue }
|
||||
) {
|
||||
return ExpectActualCheckingCompatibility.ActualFunctionWithDefaultParameters
|
||||
}
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ interface ExpectActualMatchingContext<T : DeclarationSymbolMarker> : TypeSystemC
|
||||
/**
|
||||
* Returns all symbols that are overridden by [this] symbol, including self
|
||||
*/
|
||||
fun FunctionSymbolMarker.allRecursivelyOverriddenDeclarationsIncludingSelf(): Sequence<CallableSymbolMarker>
|
||||
fun FunctionSymbolMarker.allRecursivelyOverriddenDeclarationsIncludingSelf(containingClass: RegularClassSymbolMarker?): List<CallableSymbolMarker>
|
||||
|
||||
val CallableSymbolMarker.valueParameters: List<ValueParameterSymbolMarker>
|
||||
get() = (this as? FunctionSymbolMarker)?.valueParameters ?: emptyList()
|
||||
|
||||
Reference in New Issue
Block a user