[FIR] Check conflicting overloads via scopes

Scopes may return private symbols from
supertypes, they should not clash with
symbols from the current class.

For example, see:
`FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.FakeOverride#testPrivateFakeOverrides1`

Lombok shouldn't generate functions if the
user has defined explicit ones.

In K1 generated functions are not really
added to the declared members scope.

^KT-61243 Fixed
This commit is contained in:
Nikolay Lunyak
2023-09-20 16:52:32 +03:00
committed by Space Team
parent 973248f432
commit 4e58715760
24 changed files with 278 additions and 129 deletions
@@ -5,9 +5,7 @@
package org.jetbrains.kotlin.fir.scopes
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.name.Name
abstract class FirContainingNamesAwareScope : FirScope() {
@@ -35,6 +33,56 @@ fun FirContainingNamesAwareScope.processAllCallables(processor: (FirCallableSymb
}
}
fun FirContainingNamesAwareScope.processAllClassifiers(processor: (FirClassifierSymbol<*>) -> Unit) {
for (name in getClassifierNames()) {
processClassifiersByName(name, processor)
}
}
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)