[LL FIR] fix resolution ambiguities on a complex project structure with multiple overloads on the same function

Previously, If we had multiple overloads of the same function in the same file,
then `LLFirProvider.SymbolProvider.getTopLevelPropertySymbols`
might be called with multiple copies of the same `KtFile`,
thus providing multiple copies of the same `FirNamedFunctionSymbol`.

It might be reproduced when `LLFirCombinedKotlinSymbolProvider` is used
and if nobody accessed `LLFirProvider.SymbolProvider` without a context.
A wrong result with multiple duplicating symbols will be cached in this case.

The commit fixes KT-61683 as `ConeOverloadConflictResolver` prefers actuals over expects
only in a case of valid code when an actual has a single corresponding expect.
It was not true because of the bug; thus, the problem from KT-61683 arose.

^KT-61683 fixed
This commit is contained in:
Ilya Kirillov
2023-09-04 19:22:15 +02:00
committed by Space Team
parent f14b48a4b0
commit af1cfa1cb6
@@ -135,7 +135,7 @@ internal class LLFirProvider(
callableId: CallableId,
callables: Collection<KtCallableDeclaration>
) {
destination += providerHelper.getTopLevelCallableSymbols(callableId, callables.map { it.containingKtFile })
destination += providerHelper.getTopLevelCallableSymbols(callableId, callables.mapTo(mutableSetOf()) { it.containingKtFile })
}
override fun getTopLevelFunctionSymbols(packageFqName: FqName, name: Name): List<FirNamedFunctionSymbol> {
@@ -155,7 +155,7 @@ internal class LLFirProvider(
callableId: CallableId,
functions: Collection<KtNamedFunction>
) {
destination += providerHelper.getTopLevelFunctionSymbols(callableId, functions.map { it.containingKtFile })
destination += providerHelper.getTopLevelFunctionSymbols(callableId, functions.mapTo(mutableSetOf()) { it.containingKtFile })
}
override fun getTopLevelPropertySymbols(packageFqName: FqName, name: Name): List<FirPropertySymbol> {