[FIR] Consider getter and setter for CANNOT_WEAKEN_ACCESS_PRIVILEGE
Fill source with correct value instead of null for FirDefaultPropertySetter in light tree converter
This commit is contained in:
committed by
teamcityserver
parent
b3d7ed569d
commit
0e2d765a2d
+24
-8
@@ -117,6 +117,7 @@ object FirOverrideChecker : FirClassChecker() {
|
||||
overriddenSymbols: List<FirCallableSymbol<*>>,
|
||||
context: CheckerContext
|
||||
) {
|
||||
if (overriddenSymbols.isEmpty()) return
|
||||
val visibilities = overriddenSymbols.map {
|
||||
it to it.visibility
|
||||
}.sortedBy { pair ->
|
||||
@@ -124,14 +125,29 @@ object FirOverrideChecker : FirClassChecker() {
|
||||
Visibilities.compare(visibility, pair.second) ?: Int.MIN_VALUE
|
||||
}
|
||||
|
||||
for ((overridden, overriddenVisibility) in visibilities) {
|
||||
val compare = Visibilities.compare(visibility, overriddenVisibility)
|
||||
if (compare == null) {
|
||||
reporter.reportCannotChangeAccessPrivilege(this, overridden, context)
|
||||
return
|
||||
} else if (compare < 0) {
|
||||
reporter.reportCannotWeakenAccessPrivilege(this, overridden, context)
|
||||
return
|
||||
if (this is FirPropertySymbol) {
|
||||
getterSymbol?.checkVisibility(
|
||||
containingClass,
|
||||
reporter,
|
||||
overriddenSymbols.map { (it as FirPropertySymbol).getterSymbol ?: it },
|
||||
context
|
||||
)
|
||||
setterSymbol?.checkVisibility(
|
||||
containingClass,
|
||||
reporter,
|
||||
overriddenSymbols.mapNotNull { (it as FirPropertySymbol).setterSymbol },
|
||||
context
|
||||
)
|
||||
} else {
|
||||
for ((overridden, overriddenVisibility) in visibilities) {
|
||||
val compare = Visibilities.compare(visibility, overriddenVisibility)
|
||||
if (compare == null) {
|
||||
reporter.reportCannotChangeAccessPrivilege(this, overridden, context)
|
||||
break
|
||||
} else if (compare < 0) {
|
||||
reporter.reportCannotWeakenAccessPrivilege(this, overridden, context)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-4
@@ -623,7 +623,11 @@ class DeclarationsConverter(
|
||||
)
|
||||
//parse primary constructor
|
||||
convertPrimaryConstructor(
|
||||
primaryConstructor, delegatedSelfType.source, classWrapper, delegatedConstructorSource, containingClassIsExpectClass = false
|
||||
primaryConstructor,
|
||||
delegatedSelfType.source,
|
||||
classWrapper,
|
||||
delegatedConstructorSource,
|
||||
containingClassIsExpectClass = false
|
||||
)?.let { this.declarations += it.firConstructor }
|
||||
delegateFields?.let { this.declarations += it }
|
||||
|
||||
@@ -710,7 +714,7 @@ class DeclarationsConverter(
|
||||
enumClassWrapper,
|
||||
superTypeCallEntry?.toFirSourceElement(),
|
||||
isEnumEntry = true,
|
||||
containingClassIsExpectClass = false
|
||||
containingClassIsExpectClass = false
|
||||
)?.let { declarations += it.firConstructor }
|
||||
classBodyNode?.also {
|
||||
// Use ANONYMOUS_OBJECT_NAME for the owner class id of enum entry declarations
|
||||
@@ -1117,7 +1121,11 @@ class DeclarationsConverter(
|
||||
val convertedAccessors = accessors.map { convertGetterOrSetter(it, returnType, propertyVisibility, modifiers) }
|
||||
this.getter = convertedAccessors.find { it.isGetter }
|
||||
?: FirDefaultPropertyGetter(
|
||||
null, moduleData, FirDeclarationOrigin.Source, returnType, propertyVisibility
|
||||
property.toFirSourceElement(FirFakeSourceElementKind.DefaultAccessor),
|
||||
moduleData,
|
||||
FirDeclarationOrigin.Source,
|
||||
returnType,
|
||||
propertyVisibility
|
||||
).also {
|
||||
it.status = defaultAccessorStatus()
|
||||
it.initContainingClassAttr()
|
||||
@@ -1126,7 +1134,11 @@ class DeclarationsConverter(
|
||||
this.setter = convertedAccessors.find { it.isSetter }
|
||||
?: if (isVar) {
|
||||
FirDefaultPropertySetter(
|
||||
null, moduleData, FirDeclarationOrigin.Source, returnType, propertyVisibility
|
||||
property.toFirSourceElement(FirFakeSourceElementKind.DefaultAccessor),
|
||||
moduleData,
|
||||
FirDeclarationOrigin.Source,
|
||||
returnType,
|
||||
propertyVisibility
|
||||
).also {
|
||||
it.status = defaultAccessorStatus()
|
||||
it.initContainingClassAttr()
|
||||
|
||||
+3
-2
@@ -75,15 +75,16 @@ class ValueParameter(
|
||||
isLateInit = false
|
||||
}
|
||||
annotations += this@ValueParameter.firValueParameter.annotations
|
||||
val defaultAccessorSource = propertySource?.fakeElement(FirFakeSourceElementKind.DefaultAccessor)
|
||||
getter = FirDefaultPropertyGetter(
|
||||
null,
|
||||
defaultAccessorSource,
|
||||
moduleData,
|
||||
FirDeclarationOrigin.Source,
|
||||
type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor),
|
||||
modifiers.getVisibility()
|
||||
)
|
||||
setter = if (this.isVar) FirDefaultPropertySetter(
|
||||
null,
|
||||
defaultAccessorSource,
|
||||
moduleData,
|
||||
FirDeclarationOrigin.Source,
|
||||
type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor),
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
public interface ITest {
|
||||
public var prop : Int
|
||||
get() = 12
|
||||
set(value) {}
|
||||
}
|
||||
|
||||
abstract class ATest {
|
||||
protected open var prop2 : Int
|
||||
get() = 13
|
||||
set(value) {}
|
||||
}
|
||||
|
||||
class Test: ATest(), ITest {
|
||||
override var prop : Int
|
||||
get() = 12
|
||||
private set(value) {}
|
||||
|
||||
override var prop2 : Int
|
||||
get() = 14
|
||||
<!SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY!>internal<!> set(value) {}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val test = Test()
|
||||
<!INVISIBLE_SETTER!>test.prop<!> = 12
|
||||
|
||||
val itest: ITest = test
|
||||
itest.prop = 12 // No error here
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
public interface ITest {
|
||||
public var prop : Int
|
||||
get() = 12
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
// See KT-10325: private setters are allowed for overridden properties in final class
|
||||
|
||||
interface A {
|
||||
val a: Int
|
||||
|
||||
var b: Int
|
||||
}
|
||||
|
||||
abstract class AA {
|
||||
abstract val c: Int
|
||||
|
||||
abstract var d: Int
|
||||
}
|
||||
|
||||
class B : A, AA() {
|
||||
override var a: Int = 0
|
||||
// Ok
|
||||
private set
|
||||
|
||||
override var b: Int = 1
|
||||
private set
|
||||
|
||||
override var c: Int = 2
|
||||
// Ok
|
||||
private set
|
||||
|
||||
override var d: Int = 3
|
||||
private set
|
||||
}
|
||||
|
||||
open class C : A, AA() {
|
||||
override var a: Int = 0
|
||||
// Errors here and below
|
||||
<!PRIVATE_SETTER_FOR_OPEN_PROPERTY!>private<!> set
|
||||
|
||||
override var b: Int = 1
|
||||
<!PRIVATE_SETTER_FOR_OPEN_PROPERTY!>private<!> set
|
||||
|
||||
override var c: Int = 2
|
||||
<!PRIVATE_SETTER_FOR_OPEN_PROPERTY!>private<!> set
|
||||
|
||||
override var d: Int = 3
|
||||
<!PRIVATE_SETTER_FOR_OPEN_PROPERTY!>private<!> set
|
||||
}
|
||||
|
||||
abstract class D : A, AA() {
|
||||
override var a: Int = 0
|
||||
// Errors here and below
|
||||
<!PRIVATE_SETTER_FOR_OPEN_PROPERTY!>private<!> set
|
||||
|
||||
override var b: Int = 1
|
||||
<!PRIVATE_SETTER_FOR_OPEN_PROPERTY!>private<!> set
|
||||
|
||||
override var c: Int = 2
|
||||
<!PRIVATE_SETTER_FOR_OPEN_PROPERTY!>private<!> set
|
||||
|
||||
override var d: Int = 3
|
||||
<!PRIVATE_SETTER_FOR_OPEN_PROPERTY!>private<!> set
|
||||
}
|
||||
|
||||
interface E : A {
|
||||
override var a: Int
|
||||
get() = 0
|
||||
// Errors here and below
|
||||
<!PRIVATE_SETTER_FOR_OPEN_PROPERTY!>private<!> set(arg) {}
|
||||
|
||||
override var b: Int
|
||||
get() = 0
|
||||
<!PRIVATE_SETTER_FOR_OPEN_PROPERTY!>private<!> set(arg) {}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// See KT-10325: private setters are allowed for overridden properties in final class
|
||||
|
||||
interface A {
|
||||
|
||||
Reference in New Issue
Block a user