[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>
|
override val CallableSymbolMarker.typeParameters: List<TypeParameterSymbolMarker>
|
||||||
get() = asSymbol().typeParameterSymbols
|
get() = asSymbol().typeParameterSymbols
|
||||||
|
|
||||||
override fun FunctionSymbolMarker.allRecursivelyOverriddenDeclarationsIncludingSelf(): Sequence<CallableSymbolMarker> {
|
override fun FunctionSymbolMarker.allRecursivelyOverriddenDeclarationsIncludingSelf(containingClass: RegularClassSymbolMarker?): List<CallableSymbolMarker> {
|
||||||
return when (val symbol = asSymbol()) {
|
return when (val symbol = asSymbol()) {
|
||||||
is FirConstructorSymbol, is FirFunctionWithoutNameSymbol -> sequenceOf(this)
|
is FirConstructorSymbol, is FirFunctionWithoutNameSymbol -> listOf(symbol)
|
||||||
is FirNamedFunctionSymbol -> {
|
is FirNamedFunctionSymbol -> {
|
||||||
|
if (containingClass == null) return listOf(symbol)
|
||||||
val session = symbol.moduleData.session
|
val session = symbol.moduleData.session
|
||||||
val containingClass = symbol.containingClassLookupTag()?.toFirRegularClassSymbol(session)
|
(listOf(symbol) + symbol.overriddenFunctions(containingClass.asSymbol(), session, actualScopeSession).asSequence())
|
||||||
?: return sequenceOf(symbol)
|
|
||||||
(sequenceOf(symbol) + symbol.overriddenFunctions(containingClass, session, actualScopeSession).asSequence())
|
|
||||||
// Tests work even if you don't filter out fake-overrides. Filtering fake-overrides is needed because
|
// 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.
|
// 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
|
// 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() }
|
onEnumEntry = { emptyList() }
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun FunctionSymbolMarker.allRecursivelyOverriddenDeclarationsIncludingSelf(): Sequence<CallableSymbolMarker> =
|
override fun FunctionSymbolMarker.allRecursivelyOverriddenDeclarationsIncludingSelf(containingClass: RegularClassSymbolMarker?): List<CallableSymbolMarker> =
|
||||||
when (val node = asIr()) {
|
when (val node = asIr()) {
|
||||||
is IrConstructor -> sequenceOf(this)
|
is IrConstructor -> listOf(this)
|
||||||
is IrSimpleFunction -> (sequenceOf(this) + node.overriddenSymbols)
|
is IrSimpleFunction -> (listOf(this) + node.overriddenSymbols)
|
||||||
// Tests work even if you don't filter out fake-overrides. Filtering fake-overrides is needed because
|
// 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.
|
// 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
|
// 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
|
// "parameters" checks are required only for functions, because only functions can have parameters
|
||||||
actualDeclaration is FunctionSymbolMarker && expectDeclaration is FunctionSymbolMarker
|
actualDeclaration is FunctionSymbolMarker && expectDeclaration is FunctionSymbolMarker
|
||||||
) {
|
) {
|
||||||
|
val expectOverriddenDeclarations =
|
||||||
|
expectDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf(expectContainingClass).toSet()
|
||||||
|
val actualOverriddenDeclarations =
|
||||||
|
actualDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf(actualContainingClass).toSet()
|
||||||
if (languageVersionSettings.supportsFeature(LanguageFeature.ProhibitDefaultArgumentsInExpectActualizedByFakeOverride) &&
|
if (languageVersionSettings.supportsFeature(LanguageFeature.ProhibitDefaultArgumentsInExpectActualizedByFakeOverride) &&
|
||||||
(actualDeclaration.isFakeOverride(actualContainingClass) || actualDeclaration.isDelegatedMember) &&
|
(actualDeclaration.isFakeOverride(actualContainingClass) || actualDeclaration.isDelegatedMember) &&
|
||||||
// If default params came from common supertypes of actual class and expect class then it's a valid code.
|
// 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.
|
// Here we filter out such default params.
|
||||||
(expectDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf() -
|
(expectOverriddenDeclarations - actualOverriddenDeclarations).flatMap { it.valueParameters }
|
||||||
actualDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf().toSet())
|
.any { it.hasDefaultValueNonRecursive }
|
||||||
.flatMap { it.valueParameters }.any { it.hasDefaultValueNonRecursive }
|
|
||||||
) {
|
) {
|
||||||
return ExpectActualCheckingCompatibility.DefaultArgumentsInExpectActualizedByFakeOverride
|
return ExpectActualCheckingCompatibility.DefaultArgumentsInExpectActualizedByFakeOverride
|
||||||
}
|
}
|
||||||
@@ -389,9 +392,7 @@ object AbstractExpectActualChecker {
|
|||||||
if (!actualDeclaration.isAnnotationConstructor() &&
|
if (!actualDeclaration.isAnnotationConstructor() &&
|
||||||
// If default params came from common supertypes of actual class and expect class then it's a valid code.
|
// 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.
|
// Here we filter out such default params.
|
||||||
(actualDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf() -
|
(actualOverriddenDeclarations - expectOverriddenDeclarations).flatMap { it.valueParameters }.any { it.hasDefaultValue }
|
||||||
expectDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf().toSet())
|
|
||||||
.flatMap { it.valueParameters }.any { it.hasDefaultValue }
|
|
||||||
) {
|
) {
|
||||||
return ExpectActualCheckingCompatibility.ActualFunctionWithDefaultParameters
|
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
|
* 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>
|
val CallableSymbolMarker.valueParameters: List<ValueParameterSymbolMarker>
|
||||||
get() = (this as? FunctionSymbolMarker)?.valueParameters ?: emptyList()
|
get() = (this as? FunctionSymbolMarker)?.valueParameters ?: emptyList()
|
||||||
|
|||||||
Reference in New Issue
Block a user