[FIR] Fix sources of intersection override properties's accessors

^KT-66046
This commit is contained in:
Nikolay Lunyak
2024-03-06 13:02:07 +02:00
committed by Space Team
parent daa6e03e3b
commit b7926b68ab
3 changed files with 14 additions and 8 deletions
@@ -400,9 +400,9 @@ object FirFakeOverrideGenerator {
newModality: Modality? = null, newModality: Modality? = null,
newVisibility: Visibility? = null, newVisibility: Visibility? = null,
deferredReturnTypeCalculation: DeferredCallableCopyReturnType? = null, deferredReturnTypeCalculation: DeferredCallableCopyReturnType? = null,
newSource: KtSourceElement? = derivedClassLookupTag?.toSymbol(session)?.source ?: baseProperty.source, newSource: KtSourceElement? = derivedClassLookupTag?.toSymbol(session)?.source,
): FirProperty = buildProperty { ): FirProperty = buildProperty {
source = newSource source = newSource ?: baseProperty.source
moduleData = session.nullableModuleData ?: baseProperty.moduleData moduleData = session.nullableModuleData ?: baseProperty.moduleData
this.origin = origin this.origin = origin
name = baseProperty.name name = baseProperty.name
@@ -433,6 +433,7 @@ object FirFakeOverrideGenerator {
dispatchReceiverType = dispatchReceiverType, dispatchReceiverType = dispatchReceiverType,
derivedClassLookupTag = derivedClassLookupTag, derivedClassLookupTag = derivedClassLookupTag,
baseProperty = baseProperty, baseProperty = baseProperty,
newSource = newSource ?: baseProperty.getter?.source,
) )
setter = baseProperty.setter?.buildCopyIfNeeded( setter = baseProperty.setter?.buildCopyIfNeeded(
@@ -443,6 +444,7 @@ object FirFakeOverrideGenerator {
dispatchReceiverType = dispatchReceiverType, dispatchReceiverType = dispatchReceiverType,
derivedClassLookupTag = derivedClassLookupTag, derivedClassLookupTag = derivedClassLookupTag,
baseProperty = baseProperty, baseProperty = baseProperty,
newSource = newSource ?: baseProperty.setter?.source,
) )
}.apply { }.apply {
containingClassForStaticMemberAttr = derivedClassLookupTag.takeIf { shouldOverrideSetContainingClass(baseProperty) } containingClassForStaticMemberAttr = derivedClassLookupTag.takeIf { shouldOverrideSetContainingClass(baseProperty) }
@@ -456,6 +458,7 @@ object FirFakeOverrideGenerator {
dispatchReceiverType: ConeSimpleKotlinType?, dispatchReceiverType: ConeSimpleKotlinType?,
derivedClassLookupTag: ConeClassLikeLookupTag?, derivedClassLookupTag: ConeClassLikeLookupTag?,
baseProperty: FirProperty, baseProperty: FirProperty,
newSource: KtSourceElement? = source,
) = when { ) = when {
annotations.isNotEmpty() || visibility != baseProperty.visibility -> buildCopy( annotations.isNotEmpty() || visibility != baseProperty.visibility -> buildCopy(
moduleData, moduleData,
@@ -465,6 +468,7 @@ object FirFakeOverrideGenerator {
dispatchReceiverType, dispatchReceiverType,
derivedClassLookupTag, derivedClassLookupTag,
baseProperty, baseProperty,
newSource,
) )
else -> null else -> null
} }
@@ -477,9 +481,10 @@ object FirFakeOverrideGenerator {
dispatchReceiverType: ConeSimpleKotlinType?, dispatchReceiverType: ConeSimpleKotlinType?,
derivedClassLookupTag: ConeClassLikeLookupTag?, derivedClassLookupTag: ConeClassLikeLookupTag?,
baseProperty: FirProperty, baseProperty: FirProperty,
newSource: KtSourceElement? = source,
) = when (this) { ) = when (this) {
is FirDefaultPropertyGetter -> FirDefaultPropertyGetter( is FirDefaultPropertyGetter -> FirDefaultPropertyGetter(
source = source, source = newSource,
moduleData = moduleData, moduleData = moduleData,
origin = origin, origin = origin,
propertyTypeRef = propertyReturnTypeRef, propertyTypeRef = propertyReturnTypeRef,
@@ -492,7 +497,7 @@ object FirFakeOverrideGenerator {
replaceAnnotations(this@buildCopy.annotations) replaceAnnotations(this@buildCopy.annotations)
} }
is FirDefaultPropertySetter -> FirDefaultPropertySetter( is FirDefaultPropertySetter -> FirDefaultPropertySetter(
source = source, source = newSource,
moduleData = moduleData, moduleData = moduleData,
origin = origin, origin = origin,
propertyTypeRef = propertyReturnTypeRef, propertyTypeRef = propertyReturnTypeRef,
@@ -505,6 +510,7 @@ object FirFakeOverrideGenerator {
replaceAnnotations(this@buildCopy.annotations) replaceAnnotations(this@buildCopy.annotations)
} }
else -> buildPropertyAccessorCopy(this) { else -> buildPropertyAccessorCopy(this) {
this.source = newSource
this.symbol = FirPropertyAccessorSymbol() this.symbol = FirPropertyAccessorSymbol()
this.moduleData = moduleData this.moduleData = moduleData
this.origin = origin this.origin = origin
@@ -2,14 +2,14 @@
abstract class I1 { abstract class I1 {
abstract var a: Int abstract var a: Int
<!CANNOT_WEAKEN_ACCESS_PRIVILEGE!>protected<!> set protected set
} }
interface I2 { interface I2 {
var a: Int var a: Int
} }
abstract class C : I1(), I2 abstract class <!CANNOT_WEAKEN_ACCESS_PRIVILEGE!>C<!> : I1(), I2
abstract class I3 { abstract class I3 {
protected abstract fun foo(): Int protected abstract fun foo(): Int
@@ -2,14 +2,14 @@
open class A1 { open class A1 {
var a: Int = 10 var a: Int = 10
<!CANNOT_WEAKEN_ACCESS_PRIVILEGE!>protected<!> set protected set
} }
interface I1 { interface I1 {
var a: Int var a: Int
} }
abstract class B1 : A1(), I1 abstract class <!CANNOT_WEAKEN_ACCESS_PRIVILEGE!>B1<!> : A1(), I1
open class A2 { open class A2 {
protected fun foo(): Int = 10 protected fun foo(): Int = 10