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

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

^KT-65722 Fixed

Merge-request: KT-MR-14837
This commit is contained in:
Ivan Kochurkin
2024-03-08 10:10:05 +00:00
committed by Space Team
parent 2d4f4b9bb5
commit ea44d4defd
25 changed files with 194 additions and 107 deletions
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
import org.jetbrains.kotlin.fir.backend.Fir2IrConversionScope
import org.jetbrains.kotlin.fir.backend.Fir2IrExtensions
import org.jetbrains.kotlin.fir.backend.InjectedValue
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.references.FirReference
import org.jetbrains.kotlin.ir.IrBuiltIns
@@ -103,6 +104,5 @@ class JvmFir2IrExtensions(
)
override fun hasBackingField(property: FirProperty, session: FirSession): Boolean =
// NOTE maybe there might be platform-specific logic, similar to JvmGeneratorExtensionsImpl.isPropertyWithPlatformField()
Fir2IrExtensions.Default.hasBackingField(property, session)
property.origin is FirDeclarationOrigin.Java || Fir2IrExtensions.Default.hasBackingField(property, session)
}
@@ -634,14 +634,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(property.delegate != null || extensions.hasBackingField(property, session)) {
createFieldSymbol()
}
@@ -660,7 +658,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 ->
@@ -683,7 +683,7 @@ class Fir2IrDeclarationStorage(
backingFieldForPropertyCache[irPropertySymbol] = it
propertyForBackingFieldCache[it] = irPropertySymbol
}
symbols.getterSymbol.let {
symbols.getterSymbol?.let {
getterForPropertyCache[irPropertySymbol] = it
}
symbols.setterSymbol?.let {
@@ -1597,7 +1597,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,26 +315,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
@@ -129,6 +129,7 @@ class Fir2IrLazyProperty(
}
override var backingField: IrField? = when {
symbols.backingFieldSymbol == null -> null
fir.hasExplicitBackingField -> {
val backingFieldType = with(typeConverter) {
fir.backingField?.returnTypeRef?.toIrType()
@@ -139,7 +140,7 @@ class Fir2IrLazyProperty(
this@Fir2IrLazyProperty,
fir,
IrDeclarationOrigin.PROPERTY_BACKING_FIELD,
symbols.backingFieldSymbol!!,
symbols.backingFieldSymbol,
components.visibilityConverter.convertToDescriptorVisibility(visibility),
fir.name,
fir.isVal,
@@ -149,12 +150,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,
@@ -164,21 +177,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 {
@@ -186,30 +185,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 {
@@ -223,7 +224,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
@@ -3964,6 +3964,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() {
@@ -4078,12 +4084,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() {
@@ -3964,6 +3964,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() {
@@ -4078,12 +4084,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() {