[FIR] Report OVERRIDE_DEPRECATION for overrides of HIDDEN_IN_DECLARING_CLASS_ONLY
#KT-65438 Fixed
This commit is contained in:
committed by
Space Team
parent
24367e0ad8
commit
e8cbd8a1cd
+28
-6
@@ -12,24 +12,25 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.*
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirDeprecationChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirOptInUsageBaseChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirOptInUsageBaseChecker.Experimentality
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.getContainingClassSymbol
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.hasModifier
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.unsubstitutedScope
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.overridesBackwardCompatibilityHelper
|
||||
import org.jetbrains.kotlin.fir.containingClassLookupTag
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.CallToPotentiallyHiddenSymbolResult.VisibleWithDeprecation
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.*
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.originalOrSelf
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.toConeType
|
||||
import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions
|
||||
import org.jetbrains.kotlin.fir.scopes.retrieveDirectOverriddenOf
|
||||
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
@@ -40,6 +41,8 @@ import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.fir.types.typeContext
|
||||
import org.jetbrains.kotlin.fir.visibilityChecker
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
|
||||
import org.jetbrains.kotlin.resolve.deprecation.SimpleDeprecationInfo
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
|
||||
@@ -221,7 +224,8 @@ sealed class FirOverrideChecker(mppKind: MppCheckerKind) : FirAbstractOverrideCh
|
||||
private fun FirCallableSymbol<*>.checkDeprecation(
|
||||
reporter: DiagnosticReporter,
|
||||
overriddenSymbols: List<FirCallableSymbol<*>>,
|
||||
context: CheckerContext
|
||||
context: CheckerContext,
|
||||
firTypeScope: FirTypeScope,
|
||||
) {
|
||||
val ownDeprecation = this.getDeprecation(context.session.languageVersionSettings)
|
||||
if (ownDeprecation == null || ownDeprecation.isNotEmpty()) return
|
||||
@@ -234,6 +238,24 @@ sealed class FirOverrideChecker(mppKind: MppCheckerKind) : FirAbstractOverrideCh
|
||||
reporter.reportOn(source, FirErrors.OVERRIDE_DEPRECATION, overriddenSymbol, deprecationFromOverriddenSymbol, context)
|
||||
return
|
||||
}
|
||||
|
||||
if (this is FirNamedFunctionSymbol) {
|
||||
val callableName = this.name.asString()
|
||||
|
||||
if (callableName in FirDeprecationChecker.DeprecatedOverrideOfHiddenReplacements) {
|
||||
firTypeScope.processOverriddenFunctions(this) {
|
||||
if (it.isHidden(isSuperCall = false, isOverridden = true) == VisibleWithDeprecation) {
|
||||
val message = FirDeprecationChecker.getDeprecatedOverrideOfHiddenMessage(callableName)
|
||||
val deprecationInfo =
|
||||
SimpleDeprecationInfo(DeprecationLevelValue.WARNING, propagatesToOverrides = false, message)
|
||||
reporter.reportOn(source, FirErrors.OVERRIDE_DEPRECATION, it, deprecationInfo, context)
|
||||
return@processOverriddenFunctions ProcessorAction.STOP
|
||||
}
|
||||
|
||||
ProcessorAction.NEXT
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun FirFunctionSymbol<*>.checkDefaultValues(
|
||||
@@ -342,7 +364,7 @@ sealed class FirOverrideChecker(mppKind: MppCheckerKind) : FirAbstractOverrideCh
|
||||
|
||||
member.checkVisibility(containingClass, reporter, overriddenMemberSymbols, context)
|
||||
|
||||
member.checkDeprecation(reporter, overriddenMemberSymbols, context)
|
||||
member.checkDeprecation(reporter, overriddenMemberSymbols, context, firTypeScope)
|
||||
|
||||
if (member is FirFunctionSymbol) {
|
||||
member.checkDefaultValues(reporter, context)
|
||||
|
||||
+4
@@ -1,5 +1,9 @@
|
||||
/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:(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:(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:(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:(596,604): error: Unresolved reference 'getFirst'.
|
||||
|
||||
@@ -10,8 +10,8 @@ class A<T> : ArrayList<T>() {
|
||||
super.addLast(t)
|
||||
}
|
||||
|
||||
override fun getFirst(): T = super.<!DEPRECATION!>getFirst<!>()
|
||||
override fun getLast(): T = super.<!DEPRECATION!>getLast<!>()
|
||||
override fun <!OVERRIDE_DEPRECATION!>getFirst<!>(): T = super.<!DEPRECATION!>getFirst<!>()
|
||||
override fun <!OVERRIDE_DEPRECATION!>getLast<!>(): T = super.<!DEPRECATION!>getLast<!>()
|
||||
|
||||
override fun removeFirst(): T = super.removeFirst()
|
||||
override fun removeLast(): T = super.removeLast()
|
||||
|
||||
Reference in New Issue
Block a user