FIR: set proper visibility of property accessors.
This commit is contained in:
committed by
Mikhail Glukhikh
parent
5d724a8cbc
commit
30e5748fec
+2
-2
@@ -1,11 +1,11 @@
|
||||
FILE: ifWithCR.kt
|
||||
private final var R|kotlin/Int|.readOnlyWrapper: R|kotlin/CharSequence?|
|
||||
public get(): R|kotlin/CharSequence?| {
|
||||
private get(): R|kotlin/CharSequence?| {
|
||||
^ Null(null)
|
||||
}
|
||||
private set(value: R|kotlin/CharSequence?|): R|kotlin/Unit|
|
||||
private final var R|kotlin/Int|.mutableWrapper: R|kotlin/CharSequence?|
|
||||
public get(): R|kotlin/CharSequence?| {
|
||||
private get(): R|kotlin/CharSequence?| {
|
||||
^ Null(null)
|
||||
}
|
||||
private set(value: R|kotlin/CharSequence?|): R|kotlin/Unit|
|
||||
|
||||
+29
-8
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.KtNodeTypes.*
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.builder.Context
|
||||
@@ -664,7 +665,11 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseClassOrObject
|
||||
* primaryConstructor branch
|
||||
*/
|
||||
private fun convertPrimaryConstructor(primaryConstructor: LighterASTNode?, classWrapper: ClassWrapper, delegatedConstructorSource: FirLightSourceElement?): PrimaryConstructor? {
|
||||
private fun convertPrimaryConstructor(
|
||||
primaryConstructor: LighterASTNode?,
|
||||
classWrapper: ClassWrapper,
|
||||
delegatedConstructorSource: FirLightSourceElement?
|
||||
): PrimaryConstructor? {
|
||||
if (primaryConstructor == null && !classWrapper.isEnumEntry() && classWrapper.hasSecondaryConstructor) return null
|
||||
if (classWrapper.isInterface()) return null
|
||||
|
||||
@@ -939,7 +944,8 @@ class DeclarationsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
status = FirDeclarationStatusImpl(modifiers.getVisibility(), modifiers.getModality()).apply {
|
||||
val propertyVisibility = modifiers.getVisibility()
|
||||
status = FirDeclarationStatusImpl(propertyVisibility, modifiers.getModality()).apply {
|
||||
isExpect = modifiers.hasExpect()
|
||||
isActual = modifiers.hasActual()
|
||||
isOverride = modifiers.hasOverride()
|
||||
@@ -948,13 +954,13 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
|
||||
val convertedAccessors = accessors.map { convertGetterOrSetter(it, returnType) }
|
||||
val convertedAccessors = accessors.map { convertGetterOrSetter(it, returnType, propertyVisibility) }
|
||||
this.getter = convertedAccessors.find { it.isGetter }
|
||||
?: FirDefaultPropertyGetter(null, session, FirDeclarationOrigin.Source, returnType, modifiers.getVisibility())
|
||||
?: FirDefaultPropertyGetter(null, session, FirDeclarationOrigin.Source, returnType, propertyVisibility)
|
||||
this.setter =
|
||||
if (isVar) {
|
||||
convertedAccessors.find { it.isSetter }
|
||||
?: FirDefaultPropertySetter(null, session, FirDeclarationOrigin.Source, returnType, modifiers.getVisibility())
|
||||
?: FirDefaultPropertySetter(null, session, FirDeclarationOrigin.Source, returnType, propertyVisibility)
|
||||
} else null
|
||||
|
||||
val receiver = delegateExpression?.let {
|
||||
@@ -1027,7 +1033,11 @@ class DeclarationsConverter(
|
||||
/**
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parsePropertyGetterOrSetter
|
||||
*/
|
||||
private fun convertGetterOrSetter(getterOrSetter: LighterASTNode, propertyTypeRef: FirTypeRef): FirPropertyAccessor {
|
||||
private fun convertGetterOrSetter(
|
||||
getterOrSetter: LighterASTNode,
|
||||
propertyTypeRef: FirTypeRef,
|
||||
propertyVisibility: Visibility
|
||||
): FirPropertyAccessor {
|
||||
var modifiers = Modifier()
|
||||
var isGetter = true
|
||||
var returnType: FirTypeRef? = null
|
||||
@@ -1051,10 +1061,21 @@ class DeclarationsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
var accessorVisibility = modifiers.getVisibility()
|
||||
if (accessorVisibility == Visibilities.UNKNOWN) {
|
||||
accessorVisibility = propertyVisibility
|
||||
}
|
||||
val sourceElement = getterOrSetter.toFirSourceElement()
|
||||
if (block == null && expression == null) {
|
||||
return FirDefaultPropertyAccessor
|
||||
.createGetterOrSetter(sourceElement, baseSession, FirDeclarationOrigin.Source, propertyTypeRef, modifiers.getVisibility(), isGetter)
|
||||
.createGetterOrSetter(
|
||||
sourceElement,
|
||||
baseSession,
|
||||
FirDeclarationOrigin.Source,
|
||||
propertyTypeRef,
|
||||
accessorVisibility,
|
||||
isGetter
|
||||
)
|
||||
.also {
|
||||
it.annotations += modifiers.annotations
|
||||
}
|
||||
@@ -1067,7 +1088,7 @@ class DeclarationsConverter(
|
||||
returnTypeRef = returnType ?: if (isGetter) propertyTypeRef else implicitUnitType
|
||||
symbol = FirPropertyAccessorSymbol()
|
||||
this.isGetter = isGetter
|
||||
status = FirDeclarationStatusImpl(modifiers.getVisibility(), Modality.FINAL)
|
||||
status = FirDeclarationStatusImpl(accessorVisibility, Modality.FINAL)
|
||||
context.firFunctionTargets += target
|
||||
annotations += modifiers.annotations
|
||||
|
||||
|
||||
@@ -267,11 +267,19 @@ class RawFirBuilder(
|
||||
propertyTypeRef: FirTypeRef,
|
||||
isGetter: Boolean,
|
||||
): FirPropertyAccessor {
|
||||
val accessorVisibility =
|
||||
if (this?.visibility != null && this.visibility != Visibilities.UNKNOWN) this.visibility else property.visibility
|
||||
if (this == null || !hasBody()) {
|
||||
val propertySource = property.toFirSourceElement()
|
||||
val accessorVisibility = this?.visibility ?: property.visibility
|
||||
return FirDefaultPropertyAccessor
|
||||
.createGetterOrSetter(propertySource, baseSession, FirDeclarationOrigin.Source, propertyTypeRef, accessorVisibility, isGetter)
|
||||
.createGetterOrSetter(
|
||||
propertySource,
|
||||
baseSession,
|
||||
FirDeclarationOrigin.Source,
|
||||
propertyTypeRef,
|
||||
accessorVisibility,
|
||||
isGetter
|
||||
)
|
||||
.also {
|
||||
if (this != null) {
|
||||
it.extractAnnotationsFrom(this)
|
||||
@@ -290,7 +298,7 @@ class RawFirBuilder(
|
||||
returnTypeReference.toFirOrUnitType()
|
||||
}
|
||||
this.isGetter = isGetter
|
||||
status = FirDeclarationStatusImpl(visibility, Modality.FINAL)
|
||||
status = FirDeclarationStatusImpl(accessorVisibility, Modality.FINAL)
|
||||
extractAnnotationsTo(this)
|
||||
this@RawFirBuilder.context.firFunctionTargets += accessorTarget
|
||||
extractValueParametersTo(this, propertyTypeRef)
|
||||
@@ -374,7 +382,13 @@ class RawFirBuilder(
|
||||
isLocal = false
|
||||
this.status = status
|
||||
getter = FirDefaultPropertyGetter(propertySource, baseSession, FirDeclarationOrigin.Source, type, visibility)
|
||||
setter = if (isMutable) FirDefaultPropertySetter(propertySource, baseSession, FirDeclarationOrigin.Source, type, visibility) else null
|
||||
setter = if (isMutable) FirDefaultPropertySetter(
|
||||
propertySource,
|
||||
baseSession,
|
||||
FirDeclarationOrigin.Source,
|
||||
type,
|
||||
visibility
|
||||
) else null
|
||||
extractAnnotationsTo(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
package test
|
||||
|
||||
interface A {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// !JVM_DEFAULT_MODE: enable
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// WITH_RUNTIME
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
interface A {
|
||||
// There must be no delegation methods for 'log' and 'bar' in C as they are private
|
||||
private val log: String get() = "O"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
interface Z {
|
||||
|
||||
fun testFun() : String {
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
interface Z {
|
||||
|
||||
fun testFun(): String {
|
||||
|
||||
Reference in New Issue
Block a user