FIR2IR: add workaround for SymbolTable conflicts in property/field situation

Related to KT-57049
This commit is contained in:
Mikhail Glukhikh
2023-04-28 14:23:29 +02:00
committed by Space Team
parent 6c5afa4b87
commit dbdefe90a3
@@ -868,9 +868,15 @@ class Fir2IrDeclarationStorage(
symbol = FirPropertySymbol(field.symbol.callableId) symbol = FirPropertySymbol(field.symbol.callableId)
isLocal = false isLocal = false
status = field.status status = field.status
}.apply {
isStubPropertyForPureField = true
} }
} }
private object IsStubPropertyForPureFieldKey : FirDeclarationDataKey()
private var FirProperty.isStubPropertyForPureField: Boolean? by FirDeclarationDataRegistry.data(IsStubPropertyForPureFieldKey)
fun createIrProperty( fun createIrProperty(
property: FirProperty, property: FirProperty,
irParent: IrDeclarationParent?, irParent: IrDeclarationParent?,
@@ -1467,19 +1473,32 @@ class Fir2IrDeclarationStorage(
): IrProperty { ): IrProperty {
val symbol = Fir2IrPropertySymbol(signature) val symbol = Fir2IrPropertySymbol(signature)
val firPropertySymbol = fir.symbol val firPropertySymbol = fir.symbol
val irProperty = fir.convertWithOffsets { startOffset, endOffset ->
symbolTable.declareProperty(signature, { symbol }) { fun create(startOffset: Int, endOffset: Int): Fir2IrLazyProperty {
val isFakeOverride = val isFakeOverride =
fir.isSubstitutionOrIntersectionOverride && fir.isSubstitutionOrIntersectionOverride &&
firPropertySymbol.dispatchReceiverClassLookupTagOrNull() != firPropertySymbol.dispatchReceiverClassLookupTagOrNull() !=
firPropertySymbol.originalForSubstitutionOverride?.dispatchReceiverClassLookupTagOrNull() firPropertySymbol.originalForSubstitutionOverride?.dispatchReceiverClassLookupTagOrNull()
Fir2IrLazyProperty( return Fir2IrLazyProperty(
components, startOffset, endOffset, declarationOrigin, components, startOffset, endOffset, declarationOrigin,
fir, (lazyParent as? Fir2IrLazyClass)?.fir, symbol, isFakeOverride fir, (lazyParent as? Fir2IrLazyClass)?.fir, symbol, isFakeOverride
).apply { ).apply {
this.parent = lazyParent this.parent = lazyParent
} }
} }
val irProperty = fir.convertWithOffsets { startOffset, endOffset ->
if (fir.isStubPropertyForPureField == true) {
// Very special case when two similar properties can exist so conflicts in SymbolTable are possible.
// See javaCloseFieldAndKotlinProperty.kt in BB tests
symbolTable.declarePropertyWithSignature(signature, symbol)
create(startOffset, endOffset)
symbol.owner
} else {
symbolTable.declareProperty(signature, { symbol }) {
create(startOffset, endOffset)
}
}
} }
propertyCache[fir] = irProperty propertyCache[fir] = irProperty
return irProperty return irProperty