Introduce FirProperty.hasBackingField & use it in FIR2IR
This commit is contained in:
+18
-21
@@ -674,30 +674,27 @@ class Fir2IrDeclarationStorage(
|
|||||||
val delegate = property.delegate
|
val delegate = property.delegate
|
||||||
val getter = property.getter
|
val getter = property.getter
|
||||||
val setter = property.setter
|
val setter = property.setter
|
||||||
// TODO: this checks are very preliminary, FIR resolve should determine backing field presence itself
|
|
||||||
if (property.isConst || (property.modality != Modality.ABSTRACT && (irParent !is IrClass || !irParent.isInterface))) {
|
if (property.isConst || (property.modality != Modality.ABSTRACT && (irParent !is IrClass || !irParent.isInterface))) {
|
||||||
if (initializer != null ||
|
if (property.hasBackingField) {
|
||||||
getter is FirDefaultPropertyGetter ||
|
backingField = if (delegate != null) {
|
||||||
property.isVar && setter is FirDefaultPropertySetter ||
|
createBackingField(
|
||||||
property.isReferredViaField == true
|
property, IrDeclarationOrigin.PROPERTY_DELEGATE, descriptor,
|
||||||
) {
|
components.visibilityConverter.convertToOldVisibility(property.fieldVisibility),
|
||||||
backingField = createBackingField(
|
Name.identifier("${property.name}\$delegate"), true, delegate
|
||||||
property, IrDeclarationOrigin.PROPERTY_BACKING_FIELD, descriptor,
|
)
|
||||||
components.visibilityConverter.convertToOldVisibility(property.fieldVisibility),
|
} else {
|
||||||
property.name, property.isVal, initializer, type
|
createBackingField(
|
||||||
).also { field ->
|
property, IrDeclarationOrigin.PROPERTY_BACKING_FIELD, descriptor,
|
||||||
if (initializer is FirConstExpression<*>) {
|
components.visibilityConverter.convertToOldVisibility(property.fieldVisibility),
|
||||||
// TODO: Normally we shouldn't have error type here
|
property.name, property.isVal, initializer, type
|
||||||
val constType = initializer.typeRef.toIrType().takeIf { it !is IrErrorType } ?: type
|
).also { field ->
|
||||||
field.initializer = factory.createExpressionBody(initializer.toIrConst(constType))
|
if (initializer is FirConstExpression<*>) {
|
||||||
|
// TODO: Normally we shouldn't have error type here
|
||||||
|
val constType = initializer.typeRef.toIrType().takeIf { it !is IrErrorType } ?: type
|
||||||
|
field.initializer = factory.createExpressionBody(initializer.toIrConst(constType))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (delegate != null) {
|
|
||||||
backingField = createBackingField(
|
|
||||||
property, IrDeclarationOrigin.PROPERTY_DELEGATE, descriptor,
|
|
||||||
components.visibilityConverter.convertToOldVisibility(property.fieldVisibility),
|
|
||||||
Name.identifier("${property.name}\$delegate"), true, delegate
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
if (irParent != null) {
|
if (irParent != null) {
|
||||||
backingField?.parent = irParent
|
backingField?.parent = irParent
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
|||||||
import org.jetbrains.kotlin.fir.Visibilities
|
import org.jetbrains.kotlin.fir.Visibilities
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.FirRegularClassBuilder
|
import org.jetbrains.kotlin.fir.declarations.builder.FirRegularClassBuilder
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.FirTypeParameterBuilder
|
import org.jetbrains.kotlin.fir.declarations.builder.FirTypeParameterBuilder
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirFileImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirFileImpl
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirRegularClassImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirRegularClassImpl
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousObjectSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousObjectSymbol
|
||||||
@@ -119,6 +121,13 @@ var FirProperty.isFromVararg: Boolean? by FirDeclarationDataRegistry.data(IsFrom
|
|||||||
private object IsReferredViaField : FirDeclarationDataKey()
|
private object IsReferredViaField : FirDeclarationDataKey()
|
||||||
var FirProperty.isReferredViaField: Boolean? by FirDeclarationDataRegistry.data(IsReferredViaField)
|
var FirProperty.isReferredViaField: Boolean? by FirDeclarationDataRegistry.data(IsReferredViaField)
|
||||||
|
|
||||||
|
val FirProperty.hasBackingField: Boolean
|
||||||
|
get() = initializer != null ||
|
||||||
|
getter is FirDefaultPropertyGetter ||
|
||||||
|
isVar && setter is FirDefaultPropertySetter ||
|
||||||
|
delegate != null ||
|
||||||
|
isReferredViaField == true
|
||||||
|
|
||||||
inline val FirProperty.hasJvmFieldAnnotation: Boolean
|
inline val FirProperty.hasJvmFieldAnnotation: Boolean
|
||||||
get() = annotations.any {
|
get() = annotations.any {
|
||||||
val classId = it.annotationTypeRef.coneTypeSafe<ConeClassLikeType>()?.classId
|
val classId = it.annotationTypeRef.coneTypeSafe<ConeClassLikeType>()?.classId
|
||||||
|
|||||||
Reference in New Issue
Block a user