[FIR] Use the proper processAll* functions for CONFLICTING_OVERLOADS

The `*leaf*` functions were
introduced due to my false
assumption. The normal processing
functions only collect leafs
already. `*leaf*`s are bad, because
they don't cache anything.

The change in
AbstractFirOverrideScope reflects
KT-63290, and is needed to avoid
duplicate `CONFLICTING_OVERLOADS`
and `VIRTUAL_MEMBER_HIDDEN`.
This commit is contained in:
Nikolay Lunyak
2023-11-08 11:49:35 +02:00
committed by Space Team
parent 008703c1dc
commit 80cccce8d0
5 changed files with 4 additions and 53 deletions
@@ -163,7 +163,7 @@ fun FirDeclarationCollector<FirBasedSymbol<*>>.collectClassMembers(klass: FirReg
collect(declaredFunction, FirRedeclarationPresenter.represent(declaredFunction), functionDeclarations)
unsubstitutedScope.collectLeafFunctionsByName(declaredFunction.name).forEach { anotherFunction ->
unsubstitutedScope.processFunctionsByName(declaredFunction.name) { anotherFunction ->
if (anotherFunction != declaredFunction && anotherFunction.isCollectable() && anotherFunction.isVisibleInClass(klass)) {
collect(anotherFunction, FirRedeclarationPresenter.represent(anotherFunction), functionDeclarations)
}
@@ -190,7 +190,7 @@ fun FirDeclarationCollector<FirBasedSymbol<*>>.collectClassMembers(klass: FirReg
collect(declaredProperty, FirRedeclarationPresenter.represent(declaredProperty), otherDeclarations)
unsubstitutedScope.collectLeafPropertiesByName(declaredProperty.name).forEach { anotherProperty ->
unsubstitutedScope.processPropertiesByName(declaredProperty.name) { anotherProperty ->
if (anotherProperty != declaredProperty && anotherProperty.isCollectable() && anotherProperty.isVisibleInClass(klass)) {
collect(anotherProperty, FirRedeclarationPresenter.represent(anotherProperty), otherDeclarations)
}
@@ -31,7 +31,7 @@ abstract class AbstractFirOverrideScope(
val baseDeclaration = (this as FirBasedSymbol<*>).fir as FirCallableDeclaration
val override = overrideCandidates.firstOrNull {
val overrideCandidate = (it as FirBasedSymbol<*>).fir as FirCallableDeclaration
baseDeclaration.modality != Modality.FINAL && overrideChecker.similarFunctionsOrBothProperties(
overrideChecker.similarFunctionsOrBothProperties(
overrideCandidate,
baseDeclaration
)
@@ -39,50 +39,6 @@ fun FirContainingNamesAwareScope.processAllClassifiers(processor: (FirClassifier
}
}
inline fun <reified T : FirCallableSymbol<*>> collectLeafCallablesByName(
name: Name,
processCallablesByName: (Name, (T) -> Unit) -> Unit,
crossinline processDirectlyOverriddenCallables: (T, (T) -> ProcessorAction) -> Unit,
): List<T> {
val collected = mutableSetOf<T>()
val bases = mutableSetOf<T>()
processCallablesByName(name) { function ->
processDirectlyOverriddenCallables(function) {
bases.add(it)
ProcessorAction.NEXT
}
if (function !in bases) {
collected.add(function)
}
}
return collected.filter { it !in bases }
}
fun FirTypeScope.collectLeafFunctionsByName(name: Name): List<FirNamedFunctionSymbol> =
collectLeafCallablesByName(name, ::processFunctionsByName, ::processDirectlyOverriddenFunctions)
fun FirTypeScope.collectLeafPropertiesByName(name: Name): List<FirVariableSymbol<*>> =
collectLeafCallablesByName(name, ::processPropertiesByName) { variable, process ->
if (variable is FirPropertySymbol) {
processDirectlyOverriddenProperties(variable, process)
}
}
fun FirTypeScope.collectLeafFunctions(): List<FirNamedFunctionSymbol> = buildList {
for (name in getCallableNames()) {
this += collectLeafFunctionsByName(name)
}
}
fun FirTypeScope.collectLeafProperties(): List<FirVariableSymbol<*>> = buildList {
for (name in getCallableNames()) {
this += collectLeafPropertiesByName(name)
}
}
fun FirContainingNamesAwareScope.collectAllProperties(): Collection<FirVariableSymbol<*>> {
return mutableListOf<FirVariableSymbol<*>>().apply {
processAllProperties(this::add)
@@ -1,6 +0,0 @@
enum class E {
ENTRY;
fun <!VIRTUAL_MEMBER_HIDDEN!>getDeclaringClass<!>() {}
<!ACCIDENTAL_OVERRIDE!>fun <!VIRTUAL_MEMBER_HIDDEN!>finalize<!>() {}<!>
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
enum class E {
ENTRY;