FIR: inherit property accessor modifiers from property and vice versa
This commit is contained in:
committed by
Mikhail Glukhikh
parent
6f957c7b31
commit
f64f9c2144
+6
-4
@@ -602,7 +602,9 @@ class Fir2IrDeclarationStorage(
|
||||
Name.special("<$prefix-${correspondingProperty.name}>"),
|
||||
propertyAccessor?.visibility ?: correspondingProperty.visibility,
|
||||
correspondingProperty.modality, accessorReturnType,
|
||||
isInline = false, isExternal = false, isTailrec = false, isSuspend = false, isExpect = false,
|
||||
isInline = propertyAccessor?.isInline == true,
|
||||
isExternal = propertyAccessor?.isExternal == true,
|
||||
isTailrec = false, isSuspend = false, isExpect = false,
|
||||
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||
isOperator = false
|
||||
).apply {
|
||||
@@ -659,7 +661,8 @@ class Fir2IrDeclarationStorage(
|
||||
IrFieldImpl(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
name, inferredType,
|
||||
visibility, isFinal = isFinal, isExternal = false,
|
||||
visibility, isFinal = isFinal,
|
||||
isExternal = property.isExternal,
|
||||
isStatic = property.isStatic || parent !is IrClass,
|
||||
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE
|
||||
).also {
|
||||
@@ -712,8 +715,7 @@ class Fir2IrDeclarationStorage(
|
||||
isConst = property.isConst,
|
||||
isLateinit = property.isLateInit,
|
||||
isDelegated = property.delegate != null,
|
||||
// TODO
|
||||
isExternal = false,
|
||||
isExternal = property.isExternal,
|
||||
isExpect = property.isExpect,
|
||||
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE
|
||||
).apply {
|
||||
|
||||
+24
-11
@@ -940,16 +940,8 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
val propertyVisibility = modifiers.getVisibility()
|
||||
status = FirDeclarationStatusImpl(propertyVisibility, modifiers.getModality()).apply {
|
||||
isExpect = modifiers.hasExpect()
|
||||
isActual = modifiers.hasActual()
|
||||
isOverride = modifiers.hasOverride()
|
||||
isConst = modifiers.isConst()
|
||||
isLateInit = modifiers.hasLateinit()
|
||||
}
|
||||
|
||||
|
||||
val convertedAccessors = accessors.map { convertGetterOrSetter(it, returnType, propertyVisibility) }
|
||||
val convertedAccessors = accessors.map { convertGetterOrSetter(it, returnType, propertyVisibility, modifiers) }
|
||||
this.getter = convertedAccessors.find { it.isGetter }
|
||||
?: FirDefaultPropertyGetter(null, session, FirDeclarationOrigin.Source, returnType, propertyVisibility)
|
||||
this.setter =
|
||||
@@ -958,6 +950,19 @@ class DeclarationsConverter(
|
||||
?: FirDefaultPropertySetter(null, session, FirDeclarationOrigin.Source, returnType, propertyVisibility)
|
||||
} else null
|
||||
|
||||
// Upward propagation of `inline` and `external` modifiers (from accessors to property)
|
||||
// Note that, depending on `var` or `val`, checking setter's modifiers should be careful: for `val`, setter doesn't
|
||||
// exist (null); for `var`, the retrieval of the specific modifier is supposed to be `true`
|
||||
status = FirDeclarationStatusImpl(propertyVisibility, modifiers.getModality()).apply {
|
||||
isExpect = modifiers.hasExpect()
|
||||
isActual = modifiers.hasActual()
|
||||
isOverride = modifiers.hasOverride()
|
||||
isConst = modifiers.isConst()
|
||||
isLateInit = modifiers.hasLateinit()
|
||||
isInline = modifiers.hasInline() || (getter!!.isInline && setter?.isInline != false)
|
||||
isExternal = modifiers.hasExternal() || (getter!!.isExternal && setter?.isExternal != false)
|
||||
}
|
||||
|
||||
val receiver = delegateExpression?.let {
|
||||
expressionConverter.getAsFirExpression<FirExpression>(it, "Should have delegate")
|
||||
}
|
||||
@@ -1031,7 +1036,8 @@ class DeclarationsConverter(
|
||||
private fun convertGetterOrSetter(
|
||||
getterOrSetter: LighterASTNode,
|
||||
propertyTypeRef: FirTypeRef,
|
||||
propertyVisibility: Visibility
|
||||
propertyVisibility: Visibility,
|
||||
propertyModifiers: Modifier
|
||||
): FirPropertyAccessor {
|
||||
var modifiers = Modifier()
|
||||
var isGetter = true
|
||||
@@ -1060,6 +1066,12 @@ class DeclarationsConverter(
|
||||
if (accessorVisibility == Visibilities.UNKNOWN) {
|
||||
accessorVisibility = propertyVisibility
|
||||
}
|
||||
val status =
|
||||
// Downward propagation of `inline` and `external` modifiers (from property to its accessors)
|
||||
FirDeclarationStatusImpl(accessorVisibility, Modality.FINAL).apply {
|
||||
isInline = propertyModifiers.hasInline() || modifiers.hasInline()
|
||||
isExternal = propertyModifiers.hasExternal() || modifiers.hasExternal()
|
||||
}
|
||||
val sourceElement = getterOrSetter.toFirSourceElement()
|
||||
if (block == null && expression == null) {
|
||||
return FirDefaultPropertyAccessor
|
||||
@@ -1073,6 +1085,7 @@ class DeclarationsConverter(
|
||||
)
|
||||
.also {
|
||||
it.annotations += modifiers.annotations
|
||||
it.status = status
|
||||
}
|
||||
}
|
||||
val target = FirFunctionTarget(labelName = null, isLambda = false)
|
||||
@@ -1083,7 +1096,7 @@ class DeclarationsConverter(
|
||||
returnTypeRef = returnType ?: if (isGetter) propertyTypeRef else implicitUnitType
|
||||
symbol = FirPropertyAccessorSymbol()
|
||||
this.isGetter = isGetter
|
||||
status = FirDeclarationStatusImpl(accessorVisibility, Modality.FINAL)
|
||||
this.status = status
|
||||
context.firFunctionTargets += target
|
||||
annotations += modifiers.annotations
|
||||
|
||||
|
||||
@@ -261,6 +261,14 @@ class RawFirBuilder(
|
||||
): FirPropertyAccessor {
|
||||
val accessorVisibility =
|
||||
if (this?.visibility != null && this.visibility != Visibilities.UNKNOWN) this.visibility else property.visibility
|
||||
// Downward propagation of `inline` and `external` modifiers (from property to its accessors)
|
||||
val status =
|
||||
FirDeclarationStatusImpl(accessorVisibility, Modality.FINAL).apply {
|
||||
isInline = property.hasModifier(INLINE_KEYWORD) ||
|
||||
this@toFirPropertyAccessor?.hasModifier(INLINE_KEYWORD) == true
|
||||
isExternal = property.hasModifier(EXTERNAL_KEYWORD) ||
|
||||
this@toFirPropertyAccessor?.hasModifier(EXTERNAL_KEYWORD) == true
|
||||
}
|
||||
if (this == null || !hasBody()) {
|
||||
val propertySource = property.toFirSourceElement()
|
||||
return FirDefaultPropertyAccessor
|
||||
@@ -276,6 +284,7 @@ class RawFirBuilder(
|
||||
if (this != null) {
|
||||
it.extractAnnotationsFrom(this)
|
||||
}
|
||||
it.status = status
|
||||
}
|
||||
}
|
||||
val source = this.toFirSourceElement()
|
||||
@@ -290,7 +299,7 @@ class RawFirBuilder(
|
||||
returnTypeReference.toFirOrUnitType()
|
||||
}
|
||||
this.isGetter = isGetter
|
||||
status = FirDeclarationStatusImpl(accessorVisibility, Modality.FINAL)
|
||||
this.status = status
|
||||
extractAnnotationsTo(this)
|
||||
this@RawFirBuilder.context.firFunctionTargets += accessorTarget
|
||||
extractValueParametersTo(this, propertyTypeRef)
|
||||
@@ -1078,19 +1087,25 @@ class RawFirBuilder(
|
||||
expression = { delegateExpression }.toFirExpression("Should have delegate")
|
||||
}
|
||||
} else null
|
||||
|
||||
getter = this@toFirProperty.getter.toFirPropertyAccessor(this@toFirProperty, propertyType, isGetter = true)
|
||||
setter = if (isVar) {
|
||||
this@toFirProperty.setter.toFirPropertyAccessor(this@toFirProperty, propertyType, isGetter = false)
|
||||
} else null
|
||||
|
||||
// Upward propagation of `inline` and `external` modifiers (from accessors to property)
|
||||
// Note that, depending on `var` or `val`, checking setter's modifiers should be careful: for `val`, setter doesn't
|
||||
// exist (null); for `var`, the retrieval of the specific modifier is supposed to be `true`
|
||||
status = FirDeclarationStatusImpl(visibility, modality).apply {
|
||||
isExpect = hasExpectModifier()
|
||||
isActual = hasActualModifier()
|
||||
isOverride = hasModifier(OVERRIDE_KEYWORD)
|
||||
isConst = hasModifier(CONST_KEYWORD)
|
||||
isLateInit = hasModifier(LATEINIT_KEYWORD)
|
||||
isInline = hasModifier(INLINE_KEYWORD) || (getter!!.isInline && setter?.isInline != false)
|
||||
isExternal = hasModifier(EXTERNAL_KEYWORD) || (getter!!.isExternal && setter?.isExternal != false)
|
||||
}
|
||||
|
||||
getter = this@toFirProperty.getter.toFirPropertyAccessor(this@toFirProperty, propertyType, isGetter = true)
|
||||
setter = if (isVar) {
|
||||
this@toFirProperty.setter.toFirPropertyAccessor(this@toFirProperty, propertyType, isGetter = false)
|
||||
} else null
|
||||
|
||||
val receiver = delegateExpression?.toFirExpression("Should have delegate")
|
||||
generateAccessorsByDelegate(
|
||||
delegateBuilder,
|
||||
@@ -1350,6 +1365,7 @@ class RawFirBuilder(
|
||||
else -> null
|
||||
}
|
||||
val hasSubject = subjectExpression != null
|
||||
|
||||
@OptIn(FirContractViolation::class)
|
||||
val ref = FirExpressionRef<FirWhenExpression>()
|
||||
return buildWhenExpression {
|
||||
|
||||
@@ -63,6 +63,8 @@ inline val FirMemberDeclaration.isFromEnumClass: Boolean get() = status.isFromEn
|
||||
|
||||
inline val FirPropertyAccessor.modality get() = status.modality
|
||||
inline val FirPropertyAccessor.visibility get() = status.visibility
|
||||
inline val FirPropertyAccessor.isInline get() = status.isInline
|
||||
inline val FirPropertyAccessor.isExternal get() = status.isExternal
|
||||
inline val FirPropertyAccessor.allowsToHaveFakeOverride: Boolean
|
||||
get() = !Visibilities.isPrivate(visibility) && visibility != Visibilities.INVISIBLE_FAKE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user