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

Rename `MissingFieldInJavaClass.kt` to `FieldsFromJavaClass.kt` to correspond its content

^KT-65722 Fixed
This commit is contained in:
Ivan Kochurkin
2024-02-23 11:22:44 +00:00
committed by Space Team
parent c1ea878e52
commit 1e388ad7dc
24 changed files with 192 additions and 105 deletions
@@ -591,14 +591,12 @@ class Fir2IrDeclarationStorage(
return createFakeOverridePropertySymbols(property, fakeOverrideOwnerLookupTag)
}
val isJavaOrigin = property.origin is FirDeclarationOrigin.Java
val propertySymbol = IrPropertySymbolImpl()
val getterSymbol = createFunctionSymbol(signature = null)
val getterSymbol = runIf(!isJavaOrigin) { createFunctionSymbol(signature = null) }
val setterSymbol = runIf(!isJavaOrigin && property.isVar) { createFunctionSymbol(signature = null) }
val setterSymbol = runIf(property.isVar) {
createFunctionSymbol(signature = null)
}
val backingFieldSymbol = runIf(property.delegate != null || property.hasBackingField) {
val backingFieldSymbol = runIf(isJavaOrigin || property.delegate != null || property.hasBackingField) {
createFieldSymbol()
}
@@ -617,7 +615,9 @@ class Fir2IrDeclarationStorage(
val containingClassSymbol = findContainingIrClassSymbol(property, fakeOverrideOwnerLookupTag)
val propertySymbol = IrPropertyFakeOverrideSymbol(originalSymbols.propertySymbol, containingClassSymbol, idSignature = null)
val getterSymbol = IrFunctionFakeOverrideSymbol(originalSymbols.getterSymbol, containingClassSymbol, idSignature = null)
val getterSymbol = originalSymbols.getterSymbol?.let {
IrFunctionFakeOverrideSymbol(it, containingClassSymbol, idSignature = null)
}
val setterSymbol = runIf(property.isVar) {
val setterIsVisible = property.setter?.let { setter ->
@@ -640,7 +640,7 @@ class Fir2IrDeclarationStorage(
backingFieldForPropertyCache[irPropertySymbol] = it
propertyForBackingFieldCache[it] = irPropertySymbol
}
symbols.getterSymbol.let {
symbols.getterSymbol?.let {
getterForPropertyCache[irPropertySymbol] = it
}
symbols.setterSymbol?.let {
@@ -1566,7 +1566,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?,
)
@@ -317,26 +317,28 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
if (irParent != null) {
backingField?.parent = irParent
}
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,
)
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,
)
}
}
if (property.isVar) {
if (property.isVar && symbols.setterSymbol != null) {
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,6 +111,7 @@ class Fir2IrLazyProperty(
}
override var backingField: IrField? = when {
symbols.backingFieldSymbol == null -> null
fir.hasExplicitBackingField -> {
val backingFieldType = with(typeConverter) {
fir.backingField?.returnTypeRef?.toIrType()
@@ -121,7 +122,7 @@ class Fir2IrLazyProperty(
this@Fir2IrLazyProperty,
fir,
IrDeclarationOrigin.PROPERTY_BACKING_FIELD,
symbols.backingFieldSymbol!!,
symbols.backingFieldSymbol,
components.visibilityConverter.convertToDescriptorVisibility(visibility),
fir.name,
fir.isVal,
@@ -131,12 +132,24 @@ class Fir2IrLazyProperty(
field.initializer = toIrInitializer(initializer)
}
}
extensions.hasBackingField(fir, session) && origin != IrDeclarationOrigin.FAKE_OVERRIDE -> {
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 -> {
callablesGenerator.createBackingField(
this@Fir2IrLazyProperty,
fir,
IrDeclarationOrigin.PROPERTY_BACKING_FIELD,
symbols.backingFieldSymbol!!,
symbols.backingFieldSymbol,
components.visibilityConverter.convertToDescriptorVisibility(fir.visibility),
fir.name,
fir.isVal,
@@ -146,21 +159,7 @@ class Fir2IrLazyProperty(
field.initializer = toIrInitializer(fir.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
)
}
else -> {
null
}
else -> null
}?.apply {
this.parent = this@Fir2IrLazyProperty.parent
this.annotations = fir.backingField?.annotations?.mapNotNull {
@@ -168,30 +167,32 @@ class Fir2IrLazyProperty(
}.orEmpty()
}
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 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 setter: IrSimpleFunction? = run {
if (!fir.isVar) return@run null
if (!fir.isVar || symbols.setterSymbol == null) return@run null
Fir2IrLazyPropertyAccessor(
components, startOffset, endOffset,
origin = when {
@@ -205,7 +206,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
@@ -2858,6 +2858,12 @@ 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() {
@@ -2972,12 +2978,6 @@ 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() {
@@ -2858,6 +2858,12 @@ 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() {
@@ -2972,12 +2978,6 @@ 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() {