[FIR] Report missing DEPRECATION on fake sources

#KT-60682
This commit is contained in:
Kirill Rakhman
2023-08-24 13:31:58 +02:00
committed by Space Team
parent 4e041494be
commit 61259ef34b
10 changed files with 23 additions and 28 deletions
@@ -38,30 +38,32 @@ import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
object FirDeprecationChecker : FirBasicExpressionChecker() {
private val allowedSourceKinds = setOf(
KtRealSourceElementKind,
KtFakeSourceElementKind.DesugaredIncrementOrDecrement
private val filteredSourceKinds: Set<KtFakeSourceElementKind> = setOf(
KtFakeSourceElementKind.PropertyFromParameter,
KtFakeSourceElementKind.DataClassGeneratedMembers
)
override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) {
if (!allowedSourceKinds.contains(expression.source?.kind)) return
if (expression.source?.kind in filteredSourceKinds) return
if (expression is FirAnnotation) return // checked by FirDeprecatedTypeChecker
if (expression.isLhsOfAssignment(context)) return
val calleeReference = expression.calleeReference ?: return
val resolvedReference = calleeReference.resolved ?: return
val referencedSymbol = resolvedReference.resolvedSymbol
val source = resolvedReference.source ?: expression.source
if (expression is FirDelegatedConstructorCall) {
// Report deprecations on the constructor itself, not on the declaring class as that will be handled by FirDeprecatedTypeChecker
val constructorOnlyDeprecation = referencedSymbol.getDeprecation(context.session, expression) ?: return
val isTypealiasExpansion = expression.constructedTypeRef.firClassLike(context.session)?.symbol is FirTypeAliasSymbol
reportApiStatus(
resolvedReference.source, referencedSymbol, isTypealiasExpansion,
source, referencedSymbol, isTypealiasExpansion,
constructorOnlyDeprecation, reporter, context
)
} else {
reportApiStatusIfNeeded(resolvedReference.source, referencedSymbol, context, reporter, callSite = expression)
reportApiStatusIfNeeded(source, referencedSymbol, context, reporter, callSite = expression)
}
}
@@ -2025,7 +2025,7 @@ open class PsiRawFirBuilder(
if (hasDelegate()) {
fun extractDelegateExpression() =
buildOrLazyExpression(this@toFirProperty.toFirSourceElement(KtFakeSourceElementKind.WrappedDelegate)) {
buildOrLazyExpression(this@toFirProperty.delegate?.expression?.toFirSourceElement(KtFakeSourceElementKind.WrappedDelegate)) {
this@toFirProperty.delegate?.expression?.let { expression ->
expression.toFirExpression("Should have delegate")
} ?: buildErrorExpression {
@@ -1,11 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
class Data {
@Deprecated("text")
operator fun component1(): String = throw Exception()
operator fun component2(): String = throw Exception()
}
fun use() {
val (x, y) = Data()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE
class Data {
@@ -14,3 +14,5 @@ fun use() {
A("").<!DEPRECATION!>s<!>
A(42).<!DEPRECATION!>s<!>
}
data class DC(@Deprecated("") val a: String)
@@ -19,6 +19,6 @@ class Iter2 {
}
fun use() {
for (x in Iter()) {}
for (x in Iter2()) {}
<!DEPRECATION!>for (x in Iter()) {}<!>
<!DEPRECATION, DEPRECATION!>for (x in Iter2()) {}<!>
}
@@ -1,4 +1,7 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
// IGNORE_DIAGNOSTIC_API
// IGNORE_REVERSED_RESOLVE
// ^KT-61491
import kotlin.reflect.KProperty
@@ -17,8 +20,8 @@ class PropertyHolder {
@Deprecated("text")
var name = "String"
val valDelegate by Delegate()
var varDelegate by Delegate()
val valDelegate by <!DEPRECATION!>Delegate<!>()
var varDelegate by <!DEPRECATION, DEPRECATION!>Delegate<!>()
public val test1: String = ""
@Deprecated("val-getter") get
@@ -1,4 +1,7 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
// IGNORE_DIAGNOSTIC_API
// IGNORE_REVERSED_RESOLVE
// ^KT-61491
import kotlin.reflect.KProperty
@@ -1,6 +0,0 @@
@Deprecated("No")
val f: () -> Unit = {}
fun test() {
f()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
@Deprecated("No")
val f: () -> Unit = {}