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