[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<*>>,
|
overriddenSymbols: List<FirCallableSymbol<*>>,
|
||||||
context: CheckerContext
|
context: CheckerContext
|
||||||
) {
|
) {
|
||||||
|
if (overriddenSymbols.isEmpty()) return
|
||||||
val visibilities = overriddenSymbols.map {
|
val visibilities = overriddenSymbols.map {
|
||||||
it to it.visibility
|
it to it.visibility
|
||||||
}.sortedBy { pair ->
|
}.sortedBy { pair ->
|
||||||
@@ -124,14 +125,29 @@ object FirOverrideChecker : FirClassChecker() {
|
|||||||
Visibilities.compare(visibility, pair.second) ?: Int.MIN_VALUE
|
Visibilities.compare(visibility, pair.second) ?: Int.MIN_VALUE
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((overridden, overriddenVisibility) in visibilities) {
|
if (this is FirPropertySymbol) {
|
||||||
val compare = Visibilities.compare(visibility, overriddenVisibility)
|
getterSymbol?.checkVisibility(
|
||||||
if (compare == null) {
|
containingClass,
|
||||||
reporter.reportCannotChangeAccessPrivilege(this, overridden, context)
|
reporter,
|
||||||
return
|
overriddenSymbols.map { (it as FirPropertySymbol).getterSymbol ?: it },
|
||||||
} else if (compare < 0) {
|
context
|
||||||
reporter.reportCannotWeakenAccessPrivilege(this, overridden, context)
|
)
|
||||||
return
|
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
|
//parse primary constructor
|
||||||
convertPrimaryConstructor(
|
convertPrimaryConstructor(
|
||||||
primaryConstructor, delegatedSelfType.source, classWrapper, delegatedConstructorSource, containingClassIsExpectClass = false
|
primaryConstructor,
|
||||||
|
delegatedSelfType.source,
|
||||||
|
classWrapper,
|
||||||
|
delegatedConstructorSource,
|
||||||
|
containingClassIsExpectClass = false
|
||||||
)?.let { this.declarations += it.firConstructor }
|
)?.let { this.declarations += it.firConstructor }
|
||||||
delegateFields?.let { this.declarations += it }
|
delegateFields?.let { this.declarations += it }
|
||||||
|
|
||||||
@@ -710,7 +714,7 @@ class DeclarationsConverter(
|
|||||||
enumClassWrapper,
|
enumClassWrapper,
|
||||||
superTypeCallEntry?.toFirSourceElement(),
|
superTypeCallEntry?.toFirSourceElement(),
|
||||||
isEnumEntry = true,
|
isEnumEntry = true,
|
||||||
containingClassIsExpectClass = false
|
containingClassIsExpectClass = false
|
||||||
)?.let { declarations += it.firConstructor }
|
)?.let { declarations += it.firConstructor }
|
||||||
classBodyNode?.also {
|
classBodyNode?.also {
|
||||||
// Use ANONYMOUS_OBJECT_NAME for the owner class id of enum entry declarations
|
// 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) }
|
val convertedAccessors = accessors.map { convertGetterOrSetter(it, returnType, propertyVisibility, modifiers) }
|
||||||
this.getter = convertedAccessors.find { it.isGetter }
|
this.getter = convertedAccessors.find { it.isGetter }
|
||||||
?: FirDefaultPropertyGetter(
|
?: FirDefaultPropertyGetter(
|
||||||
null, moduleData, FirDeclarationOrigin.Source, returnType, propertyVisibility
|
property.toFirSourceElement(FirFakeSourceElementKind.DefaultAccessor),
|
||||||
|
moduleData,
|
||||||
|
FirDeclarationOrigin.Source,
|
||||||
|
returnType,
|
||||||
|
propertyVisibility
|
||||||
).also {
|
).also {
|
||||||
it.status = defaultAccessorStatus()
|
it.status = defaultAccessorStatus()
|
||||||
it.initContainingClassAttr()
|
it.initContainingClassAttr()
|
||||||
@@ -1126,7 +1134,11 @@ class DeclarationsConverter(
|
|||||||
this.setter = convertedAccessors.find { it.isSetter }
|
this.setter = convertedAccessors.find { it.isSetter }
|
||||||
?: if (isVar) {
|
?: if (isVar) {
|
||||||
FirDefaultPropertySetter(
|
FirDefaultPropertySetter(
|
||||||
null, moduleData, FirDeclarationOrigin.Source, returnType, propertyVisibility
|
property.toFirSourceElement(FirFakeSourceElementKind.DefaultAccessor),
|
||||||
|
moduleData,
|
||||||
|
FirDeclarationOrigin.Source,
|
||||||
|
returnType,
|
||||||
|
propertyVisibility
|
||||||
).also {
|
).also {
|
||||||
it.status = defaultAccessorStatus()
|
it.status = defaultAccessorStatus()
|
||||||
it.initContainingClassAttr()
|
it.initContainingClassAttr()
|
||||||
|
|||||||
+3
-2
@@ -75,15 +75,16 @@ class ValueParameter(
|
|||||||
isLateInit = false
|
isLateInit = false
|
||||||
}
|
}
|
||||||
annotations += this@ValueParameter.firValueParameter.annotations
|
annotations += this@ValueParameter.firValueParameter.annotations
|
||||||
|
val defaultAccessorSource = propertySource?.fakeElement(FirFakeSourceElementKind.DefaultAccessor)
|
||||||
getter = FirDefaultPropertyGetter(
|
getter = FirDefaultPropertyGetter(
|
||||||
null,
|
defaultAccessorSource,
|
||||||
moduleData,
|
moduleData,
|
||||||
FirDeclarationOrigin.Source,
|
FirDeclarationOrigin.Source,
|
||||||
type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor),
|
type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor),
|
||||||
modifiers.getVisibility()
|
modifiers.getVisibility()
|
||||||
)
|
)
|
||||||
setter = if (this.isVar) FirDefaultPropertySetter(
|
setter = if (this.isVar) FirDefaultPropertySetter(
|
||||||
null,
|
defaultAccessorSource,
|
||||||
moduleData,
|
moduleData,
|
||||||
FirDeclarationOrigin.Source,
|
FirDeclarationOrigin.Source,
|
||||||
type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor),
|
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 interface ITest {
|
||||||
public var prop : Int
|
public var prop : Int
|
||||||
get() = 12
|
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
|
// See KT-10325: private setters are allowed for overridden properties in final class
|
||||||
|
|
||||||
interface A {
|
interface A {
|
||||||
|
|||||||
Reference in New Issue
Block a user