diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 79f4ddc89ae..84a1c88db45 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -1018,15 +1018,29 @@ class Fir2IrDeclarationStorage( */ signatureCalculator()?.let { signature -> val cachedInSymbolTable = referenceIfAny(signature) ?: return@let - if (isFakeOverride) { - val key = FakeOverrideIdentifier( - declaration.symbol.unwrapFakeOverrides(), - fakeOverrideOwnerLookupTag ?: declaration.containingClassLookupTag()!! - ) - irFakeOverridesForFirFakeOverrideMap[key] = cachedInSymbolTable - return cachedInSymbolTable - } else { - error("IR declaration with signature $signature found in SymbolTable and not found in declaration storage") + when { + isFakeOverride -> { + val key = FakeOverrideIdentifier( + declaration.symbol.unwrapFakeOverrides(), + fakeOverrideOwnerLookupTag ?: declaration.containingClassLookupTag()!! + ) + irFakeOverridesForFirFakeOverrideMap[key] = cachedInSymbolTable + return cachedInSymbolTable + } + configuration.useIrFakeOverrideBuilder -> { + /* + * If IR fake override builder is used for building fake-overrides, they are generated bypassing Fir2IrDeclarationStorage, + * and are written directly to SymbolTable. So in this case it is normal to save the result from symbol table into + * storage + * + * TODO: potentially this situation won't happen after migration from FIR2IR f/o generator to IR f/o generator (see KT-58861) + */ + cache[declaration] = cachedInSymbolTable + return cachedInSymbolTable + } + else -> { + error("IR declaration with signature $signature found in SymbolTable and not found in declaration storage") + } } }