From af1cfa1cb6e6abd10040bd9d10659cfa462a5cf7 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Mon, 4 Sep 2023 19:22:15 +0200 Subject: [PATCH] [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 --- .../analysis/low/level/api/fir/providers/LLFirProvider.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/providers/LLFirProvider.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/providers/LLFirProvider.kt index bf2aff36a85..5d1625aaf90 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/providers/LLFirProvider.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/providers/LLFirProvider.kt @@ -135,7 +135,7 @@ internal class LLFirProvider( callableId: CallableId, callables: Collection ) { - 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 { @@ -155,7 +155,7 @@ internal class LLFirProvider( callableId: CallableId, functions: Collection ) { - 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 {