[FIR] Report deprecation on synthetic property calls on super receivers

#KT-65438 Fixed
This commit is contained in:
Kirill Rakhman
2024-02-13 18:07:46 +01:00
committed by Space Team
parent 35e9170af1
commit e39af4583e
7 changed files with 64 additions and 40 deletions
@@ -46,6 +46,7 @@ class FirSyntheticPropertiesScope private constructor(
private val dispatchReceiverType: ConeKotlinType,
private val syntheticNamesProvider: FirSyntheticNamesProvider,
private val returnTypeCalculator: ReturnTypeCalculator?,
private val isSuperCall: Boolean,
) : FirContainingNamesAwareScope() {
companion object {
fun createIfSyntheticNamesProviderIsDefined(
@@ -53,6 +54,7 @@ class FirSyntheticPropertiesScope private constructor(
dispatchReceiverType: ConeKotlinType,
baseScope: FirTypeScope,
returnTypeCalculator: ReturnTypeCalculator? = null,
isSuperCall: Boolean = false,
): FirSyntheticPropertiesScope? {
val syntheticNamesProvider = session.syntheticNamesProvider ?: return null
return FirSyntheticPropertiesScope(
@@ -61,6 +63,7 @@ class FirSyntheticPropertiesScope private constructor(
dispatchReceiverType,
syntheticNamesProvider,
returnTypeCalculator,
isSuperCall,
)
}
}
@@ -229,7 +232,7 @@ class FirSyntheticPropertiesScope private constructor(
baseScope.processDirectOverriddenFunctionsWithBaseScope(symbolToStart) l@{ symbol, scope ->
if (hasMatchingSetter) return@l ProcessorAction.STOP
val baseDispatchReceiverType = symbol.dispatchReceiverType ?: return@l ProcessorAction.NEXT
val syntheticScope = FirSyntheticPropertiesScope(session, scope, baseDispatchReceiverType, syntheticNamesProvider, returnTypeCalculator)
val syntheticScope = FirSyntheticPropertiesScope(session, scope, baseDispatchReceiverType, syntheticNamesProvider, returnTypeCalculator, isSuperCall)
val baseProperties = syntheticScope.getProperties(propertyName)
val propertyFound = baseProperties.any {
val baseProperty = it.fir
@@ -272,7 +275,7 @@ class FirSyntheticPropertiesScope private constructor(
val visited = mutableSetOf<MemberWithBaseScope<FirNamedFunctionSymbol>>()
fun checkJavaOrigin(symbol: FirNamedFunctionSymbol, scope: FirTypeScope, isOverridden: Boolean) {
val hidden = symbol.hiddenStatusOfCall(isSuperCall = false, isCallToOverride = isOverridden)
val hidden = symbol.hiddenStatusOfCall(isSuperCall = isSuperCall, isCallToOverride = isOverridden)
when (hidden) {
CallToPotentiallyHiddenSymbolResult.Hidden -> isHiddenEverywhereBesideSuperCalls = true
CallToPotentiallyHiddenSymbolResult.VisibleWithDeprecation -> isDeprecatedOverrideOfHidden = true
@@ -802,12 +802,11 @@ internal object CheckHiddenDeclaration : ResolutionStage() {
return hidden
}
private fun FirElement.isSuperCall(session: FirSession): Boolean =
this is FirQualifiedAccessExpression && explicitReceiver?.toReference(session) is FirSuperReference
}
internal fun FirElement.isSuperCall(session: FirSession): Boolean =
this is FirQualifiedAccessExpression && explicitReceiver?.toReference(session) is FirSuperReference
private val DYNAMIC_EXTENSION_ANNOTATION_CLASS_ID: ClassId = ClassId.topLevel(DYNAMIC_EXTENSION_FQ_NAME)
internal object ProcessDynamicExtensionAnnotation : ResolutionStage() {
@@ -81,6 +81,7 @@ class MemberScopeTowerLevel(
private val session: FirSession get() = bodyResolveComponents.session
private fun <T : FirCallableSymbol<*>> processMembers(
info: CallInfo,
output: TowerScopeLevelProcessor<T>,
processScopeMembers: FirScope.(processor: (T) -> Unit) -> Unit
): ProcessResult {
@@ -165,6 +166,7 @@ class MemberScopeTowerLevel(
typeForSyntheticScope,
useSiteForSyntheticScope,
bodyResolveComponents.returnTypeCalculator,
isSuperCall = info.callSite.isSuperCall(session),
)
withSynthetic?.processScopeMembers { symbol ->
@@ -274,7 +276,7 @@ class MemberScopeTowerLevel(
processor: TowerScopeLevelProcessor<FirFunctionSymbol<*>>
): ProcessResult {
val lookupTracker = session.lookupTracker
return processMembers(processor) { consumer ->
return processMembers(info, processor) { consumer ->
withMemberCallLookup(lookupTracker, info) { lookupCtx ->
this.processFunctionsAndConstructorsByName(
info, session, bodyResolveComponents,
@@ -294,7 +296,7 @@ class MemberScopeTowerLevel(
processor: TowerScopeLevelProcessor<FirVariableSymbol<*>>
): ProcessResult {
val lookupTracker = session.lookupTracker
return processMembers(processor) { consumer ->
return processMembers(info, processor) { consumer ->
withMemberCallLookup(lookupTracker, info) { lookupCtx ->
lookupTracker?.recordCallLookup(info, dispatchReceiverValue.type)
this.processPropertiesByName(info.name) {
@@ -1,49 +1,55 @@
/newListMethods.kt:13:18: warning: this declaration overrides deprecated member but not marked as deprecated itself. Please add @Deprecated annotation or suppress. See https://youtrack.jetbrains.com/issue/KT-47902 for details
/newListMethods.kt:15:18: warning: this declaration overrides deprecated member but not marked as deprecated itself. Please add @Deprecated annotation or suppress. See https://youtrack.jetbrains.com/issue/KT-47902 for details
override fun getFirst(): T = super.getFirst()
^^^^^^^^
/newListMethods.kt:13:40: warning: 'getFirst(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
/newListMethods.kt:15:40: warning: 'getFirst(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
override fun getFirst(): T = super.getFirst()
^^^^^^^^
/newListMethods.kt:14:18: warning: this declaration overrides deprecated member but not marked as deprecated itself. Please add @Deprecated annotation or suppress. See https://youtrack.jetbrains.com/issue/KT-47902 for details
/newListMethods.kt:16:18: warning: this declaration overrides deprecated member but not marked as deprecated itself. Please add @Deprecated annotation or suppress. See https://youtrack.jetbrains.com/issue/KT-47902 for details
override fun getLast(): T = super.getLast()
^^^^^^^
/newListMethods.kt:14:39: warning: 'getLast(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
/newListMethods.kt:16:39: warning: 'getLast(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
override fun getLast(): T = super.getLast()
^^^^^^^
/newListMethods.kt:25:7: warning: 'getFirst(): E!' is deprecated. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
/newListMethods.kt:18:34: warning: 'getFirst(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
fun superFirst2(): T = super.first
^^^^^
/newListMethods.kt:19:33: warning: 'getLast(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
fun superLast2(): T = super.last
^^^^
/newListMethods.kt:30:7: warning: 'getFirst(): E!' is deprecated. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
x.getFirst()
^^^^^^^^
/newListMethods.kt:26:7: warning: 'getter for first: E!' is deprecated. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
/newListMethods.kt:31:7: warning: 'getter for first: E!' is deprecated. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
x.first // synthetic property for getFirst()
^^^^^
/newListMethods.kt:28:7: warning: 'getLast(): E!' is deprecated. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
/newListMethods.kt:33:7: warning: 'getLast(): E!' is deprecated. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
x.getLast()
^^^^^^^
/newListMethods.kt:29:7: warning: 'getter for last: E!' is deprecated. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
/newListMethods.kt:34:7: warning: 'getter for last: E!' is deprecated. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
x.last
^^^^
/newListMethods.kt:37:7: warning: 'getFirst(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
/newListMethods.kt:42:7: warning: 'getFirst(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
y.getFirst()
^^^^^^^^
/newListMethods.kt:38:7: warning: 'getFirst(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
/newListMethods.kt:43:7: warning: 'getFirst(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
y.first
^^^^^
/newListMethods.kt:40:7: warning: 'getLast(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
/newListMethods.kt:45:7: warning: 'getLast(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
y.getLast()
^^^^^^^
/newListMethods.kt:41:7: warning: 'getLast(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
/newListMethods.kt:46:7: warning: 'getLast(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
y.last
^^^^
/newListMethods.kt:49:7: warning: 'getFirst(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
/newListMethods.kt:54:7: warning: 'getFirst(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
z.getFirst()
^^^^^^^^
/newListMethods.kt:50:7: warning: 'getFirst(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
/newListMethods.kt:55:7: warning: 'getFirst(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getFirst()' member of List is redundant in Kotlin and might be removed soon. Please use 'first()' stdlib extension instead
z.first
^^^^^
/newListMethods.kt:52:7: warning: 'getLast(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
/newListMethods.kt:57:7: warning: 'getLast(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
z.getLast()
^^^^^^^
/newListMethods.kt:53:7: warning: 'getLast(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
/newListMethods.kt:58:7: warning: 'getLast(): E!' is deprecated. Overrides deprecated member in 'java.util.AbstractList'. 'getLast()' member of List is redundant in Kotlin and might be removed soon. Please use 'last()' stdlib extension instead
z.last
^^^^
@@ -1,31 +1,35 @@
/newListMethods.fir.kt:(231,239): warning: This declaration overrides a deprecated member but is not marked as deprecated itself. Please add the '@Deprecated' annotation or suppress the diagnostic.
/newListMethods.fir.kt:(337,345): warning: This declaration overrides a deprecated member but is not marked as deprecated itself. Please add the '@Deprecated' annotation or suppress the diagnostic.
/newListMethods.fir.kt:(253,261): warning: 'fun getFirst(): T!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'first()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(359,367): warning: 'fun getFirst(): T!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'first()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(281,288): warning: This declaration overrides a deprecated member but is not marked as deprecated itself. Please add the '@Deprecated' annotation or suppress the diagnostic.
/newListMethods.fir.kt:(387,394): warning: This declaration overrides a deprecated member but is not marked as deprecated itself. Please add the '@Deprecated' annotation or suppress the diagnostic.
/newListMethods.fir.kt:(302,309): warning: 'fun getLast(): T!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'last()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(408,415): warning: 'fun getLast(): T!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'last()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(596,604): error: Unresolved reference 'getFirst'.
/newListMethods.fir.kt:(452,457): warning: 'val first: T!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'first()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(613,618): error: Function invocation 'first()' expected.
/newListMethods.fir.kt:(490,494): warning: 'val last: T!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'last()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(704,711): error: Unresolved reference 'getLast'.
/newListMethods.fir.kt:(779,787): error: Unresolved reference 'getFirst'.
/newListMethods.fir.kt:(720,724): error: Function invocation 'last()' expected.
/newListMethods.fir.kt:(796,801): error: Function invocation 'first()' expected.
/newListMethods.fir.kt:(838,846): warning: 'fun getFirst(): String!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'first()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(887,894): error: Unresolved reference 'getLast'.
/newListMethods.fir.kt:(855,860): warning: 'val first: String!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'first()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(903,907): error: Function invocation 'last()' expected.
/newListMethods.fir.kt:(881,888): warning: 'fun getLast(): String!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'last()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(1021,1029): warning: 'fun getFirst(): String!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'first()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(897,901): warning: 'val last: String!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'last()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(1038,1043): warning: 'val first: String!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'first()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(1015,1023): warning: 'fun getFirst(): String' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'first()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(1064,1071): warning: 'fun getLast(): String!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'last()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(1032,1037): warning: 'val first: String' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'first()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(1080,1084): warning: 'val last: String!' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'last()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(1058,1065): warning: 'fun getLast(): String' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'last()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(1198,1206): warning: 'fun getFirst(): String' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'first()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(1074,1078): warning: 'val last: String' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'last()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(1215,1220): warning: 'val first: String' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'first()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(1241,1248): warning: 'fun getLast(): String' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'last()' stdlib extension if the collection supports fast random access.
/newListMethods.fir.kt:(1257,1261): warning: 'val last: String' is deprecated. This declaration will be renamed in a future version of Kotlin. Please consider using the 'last()' stdlib extension if the collection supports fast random access.
@@ -1,5 +1,7 @@
// ISSUE: KT-58371
// RENDER_DIAGNOSTICS_FULL_TEXT
// DIAGNOSTICS: -SUPER_CANT_BE_EXTENSION_RECEIVER
// ^Otherwise only K1 errors are written to .diag file.
class A<T> : ArrayList<T>() {
override fun addFirst(t: T) {
@@ -13,6 +15,9 @@ class A<T> : ArrayList<T>() {
override fun <!OVERRIDE_DEPRECATION!>getFirst<!>(): T = super.<!DEPRECATION!>getFirst<!>()
override fun <!OVERRIDE_DEPRECATION!>getLast<!>(): T = super.<!DEPRECATION!>getLast<!>()
fun superFirst2(): T = super.<!DEPRECATION!>first<!>
fun superLast2(): T = super.<!DEPRECATION!>last<!>
override fun removeFirst(): T = super.removeFirst()
override fun removeLast(): T = super.removeLast()
@@ -1,5 +1,7 @@
// ISSUE: KT-58371
// RENDER_DIAGNOSTICS_FULL_TEXT
// DIAGNOSTICS: -SUPER_CANT_BE_EXTENSION_RECEIVER
// ^Otherwise only K1 errors are written to .diag file.
class A<T> : ArrayList<T>() {
override fun addFirst(t: T) {
@@ -13,6 +15,9 @@ class A<T> : ArrayList<T>() {
override fun <!OVERRIDE_DEPRECATION!>getFirst<!>(): T = super.<!DEPRECATION!>getFirst<!>()
override fun <!OVERRIDE_DEPRECATION!>getLast<!>(): T = super.<!DEPRECATION!>getLast<!>()
fun superFirst2(): T = super.<!DEPRECATION!>first<!>
fun superLast2(): T = super.<!DEPRECATION!>last<!>
override fun removeFirst(): T = super.removeFirst()
override fun removeLast(): T = super.removeLast()