Revert "[FIR2IR] Remove non-existent accessors from property references on Java fields"

This reverts commit 1e388ad7dc.
This commit is contained in:
Dmitriy Novozhilov
2024-02-28 08:08:43 +02:00
committed by Space Team
parent d899618f9a
commit 2febc807a1
24 changed files with 105 additions and 192 deletions
@@ -599,12 +599,14 @@ class Fir2IrDeclarationStorage(
return createFakeOverridePropertySymbols(property, fakeOverrideOwnerLookupTag)
}
val isJavaOrigin = property.origin is FirDeclarationOrigin.Java
val propertySymbol = IrPropertySymbolImpl()
val getterSymbol = runIf(!isJavaOrigin) { createFunctionSymbol(signature = null) }
val setterSymbol = runIf(!isJavaOrigin && property.isVar) { createFunctionSymbol(signature = null) }
val getterSymbol = createFunctionSymbol(signature = null)
val backingFieldSymbol = runIf(isJavaOrigin || property.delegate != null || property.hasBackingField) {
val setterSymbol = runIf(property.isVar) {
createFunctionSymbol(signature = null)
}
val backingFieldSymbol = runIf(property.delegate != null || property.hasBackingField) {
createFieldSymbol()
}
@@ -623,9 +625,7 @@ class Fir2IrDeclarationStorage(
val containingClassSymbol = findContainingIrClassSymbol(property, fakeOverrideOwnerLookupTag)
val propertySymbol = IrPropertyFakeOverrideSymbol(originalSymbols.propertySymbol, containingClassSymbol, idSignature = null)
val getterSymbol = originalSymbols.getterSymbol?.let {
IrFunctionFakeOverrideSymbol(it, containingClassSymbol, idSignature = null)
}
val getterSymbol = IrFunctionFakeOverrideSymbol(originalSymbols.getterSymbol, containingClassSymbol, idSignature = null)
val setterSymbol = runIf(property.isVar) {
val setterIsVisible = property.setter?.let { setter ->
@@ -648,7 +648,7 @@ class Fir2IrDeclarationStorage(
backingFieldForPropertyCache[irPropertySymbol] = it
propertyForBackingFieldCache[it] = irPropertySymbol
}
symbols.getterSymbol?.let {
symbols.getterSymbol.let {
getterForPropertyCache[irPropertySymbol] = it
}
symbols.setterSymbol?.let {
@@ -1562,7 +1562,7 @@ internal fun <D : IrDeclaration> IrBindableSymbol<*, D>.ownerIfBound(): D? {
data class PropertySymbols(
val propertySymbol: IrPropertySymbol,
val getterSymbol: IrSimpleFunctionSymbol?,
val getterSymbol: IrSimpleFunctionSymbol,
val setterSymbol: IrSimpleFunctionSymbol?,
val backingFieldSymbol: IrFieldSymbol?,
)
@@ -315,28 +315,26 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
if (irParent != null) {
backingField?.parent = irParent
}
this.getter = symbols.getterSymbol?.let { getterSymbol ->
getter.convertWithOffsets(startOffset, endOffset) { startOffset, endOffset ->
createIrPropertyAccessor(
getter, property, this, getterSymbol, type, irParent, false,
when {
origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB -> origin
origin == IrDeclarationOrigin.ENUM_CLASS_SPECIAL_MEMBER -> origin
delegate != null -> IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR
origin == IrDeclarationOrigin.FAKE_OVERRIDE -> origin
origin == IrDeclarationOrigin.DELEGATED_MEMBER -> origin
getter == null || getter is FirDefaultPropertyGetter -> IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR
else -> origin
},
startOffset, endOffset,
property.unwrapFakeOverrides().getter,
)
}
this.getter = getter.convertWithOffsets(startOffset, endOffset) { startOffset, endOffset ->
createIrPropertyAccessor(
getter, property, this, symbols.getterSymbol, type, irParent, false,
when {
origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB -> origin
origin == IrDeclarationOrigin.ENUM_CLASS_SPECIAL_MEMBER -> origin
delegate != null -> IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR
origin == IrDeclarationOrigin.FAKE_OVERRIDE -> origin
origin == IrDeclarationOrigin.DELEGATED_MEMBER -> origin
getter == null || getter is FirDefaultPropertyGetter -> IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR
else -> origin
},
startOffset, endOffset,
property.unwrapFakeOverrides().getter,
)
}
if (property.isVar && symbols.setterSymbol != null) {
if (property.isVar) {
this.setter = setter.convertWithOffsets(startOffset, endOffset) { startOffset, endOffset ->
createIrPropertyAccessor(
setter, property, this, symbols.setterSymbol, type, irParent, true,
setter, property, this, symbols.setterSymbol!!, type, irParent, true,
when {
delegate != null -> IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR
origin == IrDeclarationOrigin.FAKE_OVERRIDE -> origin
@@ -111,7 +111,6 @@ class Fir2IrLazyProperty(
}
override var backingField: IrField? = when {
symbols.backingFieldSymbol == null -> null
fir.hasExplicitBackingField -> {
val backingFieldType = with(typeConverter) {
fir.backingField?.returnTypeRef?.toIrType()
@@ -122,7 +121,7 @@ class Fir2IrLazyProperty(
this@Fir2IrLazyProperty,
fir,
IrDeclarationOrigin.PROPERTY_BACKING_FIELD,
symbols.backingFieldSymbol,
symbols.backingFieldSymbol!!,
components.visibilityConverter.convertToDescriptorVisibility(visibility),
fir.name,
fir.isVal,
@@ -132,24 +131,12 @@ class Fir2IrLazyProperty(
field.initializer = toIrInitializer(initializer)
}
}
fir.delegate != null -> {
callablesGenerator.createBackingField(
this@Fir2IrLazyProperty,
fir,
IrDeclarationOrigin.PROPERTY_DELEGATE,
symbols.backingFieldSymbol,
components.visibilityConverter.convertToDescriptorVisibility(fir.visibility),
NameUtils.propertyDelegateName(fir.name),
true,
fir.delegate
)
}
origin != IrDeclarationOrigin.FAKE_OVERRIDE -> {
extensions.hasBackingField(fir, session) && origin != IrDeclarationOrigin.FAKE_OVERRIDE -> {
callablesGenerator.createBackingField(
this@Fir2IrLazyProperty,
fir,
IrDeclarationOrigin.PROPERTY_BACKING_FIELD,
symbols.backingFieldSymbol,
symbols.backingFieldSymbol!!,
components.visibilityConverter.convertToDescriptorVisibility(fir.visibility),
fir.name,
fir.isVal,
@@ -159,7 +146,21 @@ class Fir2IrLazyProperty(
field.initializer = toIrInitializer(fir.initializer)
}
}
else -> null
fir.delegate != null -> {
callablesGenerator.createBackingField(
this@Fir2IrLazyProperty,
fir,
IrDeclarationOrigin.PROPERTY_DELEGATE,
symbols.backingFieldSymbol!!,
components.visibilityConverter.convertToDescriptorVisibility(fir.visibility),
NameUtils.propertyDelegateName(fir.name),
true,
fir.delegate
)
}
else -> {
null
}
}?.apply {
this.parent = this@Fir2IrLazyProperty.parent
this.annotations = fir.backingField?.annotations?.mapNotNull {
@@ -167,32 +168,30 @@ class Fir2IrLazyProperty(
}.orEmpty()
}
override var getter: IrSimpleFunction? = symbols.getterSymbol?.let {
Fir2IrLazyPropertyAccessor(
components, startOffset, endOffset,
origin = when {
origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB -> origin
fir.delegate != null -> IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR
origin == IrDeclarationOrigin.FAKE_OVERRIDE -> origin
origin == IrDeclarationOrigin.DELEGATED_MEMBER -> origin
fir.getter is FirDefaultPropertyGetter -> IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR
else -> origin
},
firAccessor = fir.getter,
isSetter = false,
firParentProperty = fir,
firParentClass = containingClass,
symbol = it,
parent = this@Fir2IrLazyProperty.parent,
isFakeOverride = isFakeOverride,
correspondingPropertySymbol = this.symbol
).apply {
classifiersGenerator.setTypeParameters(this, this@Fir2IrLazyProperty.fir, ConversionTypeOrigin.DEFAULT)
}
override var getter: IrSimpleFunction? = Fir2IrLazyPropertyAccessor(
components, startOffset, endOffset,
origin = when {
origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB -> origin
fir.delegate != null -> IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR
origin == IrDeclarationOrigin.FAKE_OVERRIDE -> origin
origin == IrDeclarationOrigin.DELEGATED_MEMBER -> origin
fir.getter is FirDefaultPropertyGetter -> IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR
else -> origin
},
firAccessor = fir.getter,
isSetter = false,
firParentProperty = fir,
firParentClass = containingClass,
symbol = symbols.getterSymbol,
parent = this@Fir2IrLazyProperty.parent,
isFakeOverride = isFakeOverride,
correspondingPropertySymbol = this.symbol
).apply {
classifiersGenerator.setTypeParameters(this, this@Fir2IrLazyProperty.fir, ConversionTypeOrigin.DEFAULT)
}
override var setter: IrSimpleFunction? = run {
if (!fir.isVar || symbols.setterSymbol == null) return@run null
if (!fir.isVar) return@run null
Fir2IrLazyPropertyAccessor(
components, startOffset, endOffset,
origin = when {
@@ -206,7 +205,7 @@ class Fir2IrLazyProperty(
firAccessor = fir.setter, isSetter = true,
firParentProperty = fir,
firParentClass = containingClass,
symbol = symbols.setterSymbol,
symbol = symbols.setterSymbol!!,
parent = this@Fir2IrLazyProperty.parent,
isFakeOverride = isFakeOverride,
correspondingPropertySymbol = this.symbol
@@ -2876,12 +2876,6 @@ public class FirLightTreeJvmIrTextTestGenerated extends AbstractFirLightTreeJvmI
runTest("compiler/testData/ir/irText/firProblems/FakeOverrideInAnonymousWithDelegation.kt");
}
@Test
@TestMetadata("FieldsFromJavaClass.kt")
public void testFieldsFromJavaClass() {
runTest("compiler/testData/ir/irText/firProblems/FieldsFromJavaClass.kt");
}
@Test
@TestMetadata("Fir2IrClassifierStorage.kt")
public void testFir2IrClassifierStorage() {
@@ -2996,6 +2990,12 @@ public class FirLightTreeJvmIrTextTestGenerated extends AbstractFirLightTreeJvmI
runTest("compiler/testData/ir/irText/firProblems/LocalSuspendFun.kt");
}
@Test
@TestMetadata("MissingFieldInJavaClass.kt")
public void testMissingFieldInJavaClass() {
runTest("compiler/testData/ir/irText/firProblems/MissingFieldInJavaClass.kt");
}
@Test
@TestMetadata("Modality.kt")
public void testModality() {
@@ -2876,12 +2876,6 @@ public class FirPsiJvmIrTextTestGenerated extends AbstractFirPsiJvmIrTextTest {
runTest("compiler/testData/ir/irText/firProblems/FakeOverrideInAnonymousWithDelegation.kt");
}
@Test
@TestMetadata("FieldsFromJavaClass.kt")
public void testFieldsFromJavaClass() {
runTest("compiler/testData/ir/irText/firProblems/FieldsFromJavaClass.kt");
}
@Test
@TestMetadata("Fir2IrClassifierStorage.kt")
public void testFir2IrClassifierStorage() {
@@ -2996,6 +2990,12 @@ public class FirPsiJvmIrTextTestGenerated extends AbstractFirPsiJvmIrTextTest {
runTest("compiler/testData/ir/irText/firProblems/LocalSuspendFun.kt");
}
@Test
@TestMetadata("MissingFieldInJavaClass.kt")
public void testMissingFieldInJavaClass() {
runTest("compiler/testData/ir/irText/firProblems/MissingFieldInJavaClass.kt");
}
@Test
@TestMetadata("Modality.kt")
public void testModality() {