[FIR] Report missing DEPRECATION on fake sources
#KT-60682
This commit is contained in:
committed by
Space Team
parent
4e041494be
commit
61259ef34b
+8
-6
@@ -38,30 +38,32 @@ import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
|
|||||||
|
|
||||||
object FirDeprecationChecker : FirBasicExpressionChecker() {
|
object FirDeprecationChecker : FirBasicExpressionChecker() {
|
||||||
|
|
||||||
private val allowedSourceKinds = setOf(
|
private val filteredSourceKinds: Set<KtFakeSourceElementKind> = setOf(
|
||||||
KtRealSourceElementKind,
|
KtFakeSourceElementKind.PropertyFromParameter,
|
||||||
KtFakeSourceElementKind.DesugaredIncrementOrDecrement
|
KtFakeSourceElementKind.DataClassGeneratedMembers
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) {
|
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 is FirAnnotation) return // checked by FirDeprecatedTypeChecker
|
||||||
if (expression.isLhsOfAssignment(context)) return
|
if (expression.isLhsOfAssignment(context)) return
|
||||||
|
|
||||||
val calleeReference = expression.calleeReference ?: return
|
val calleeReference = expression.calleeReference ?: return
|
||||||
val resolvedReference = calleeReference.resolved ?: return
|
val resolvedReference = calleeReference.resolved ?: return
|
||||||
val referencedSymbol = resolvedReference.resolvedSymbol
|
val referencedSymbol = resolvedReference.resolvedSymbol
|
||||||
|
val source = resolvedReference.source ?: expression.source
|
||||||
|
|
||||||
if (expression is FirDelegatedConstructorCall) {
|
if (expression is FirDelegatedConstructorCall) {
|
||||||
// Report deprecations on the constructor itself, not on the declaring class as that will be handled by FirDeprecatedTypeChecker
|
// 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 constructorOnlyDeprecation = referencedSymbol.getDeprecation(context.session, expression) ?: return
|
||||||
val isTypealiasExpansion = expression.constructedTypeRef.firClassLike(context.session)?.symbol is FirTypeAliasSymbol
|
val isTypealiasExpansion = expression.constructedTypeRef.firClassLike(context.session)?.symbol is FirTypeAliasSymbol
|
||||||
|
|
||||||
reportApiStatus(
|
reportApiStatus(
|
||||||
resolvedReference.source, referencedSymbol, isTypealiasExpansion,
|
source, referencedSymbol, isTypealiasExpansion,
|
||||||
constructorOnlyDeprecation, reporter, context
|
constructorOnlyDeprecation, reporter, context
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
reportApiStatusIfNeeded(resolvedReference.source, referencedSymbol, context, reporter, callSite = expression)
|
reportApiStatusIfNeeded(source, referencedSymbol, context, reporter, callSite = expression)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2025,7 +2025,7 @@ open class PsiRawFirBuilder(
|
|||||||
|
|
||||||
if (hasDelegate()) {
|
if (hasDelegate()) {
|
||||||
fun extractDelegateExpression() =
|
fun extractDelegateExpression() =
|
||||||
buildOrLazyExpression(this@toFirProperty.toFirSourceElement(KtFakeSourceElementKind.WrappedDelegate)) {
|
buildOrLazyExpression(this@toFirProperty.delegate?.expression?.toFirSourceElement(KtFakeSourceElementKind.WrappedDelegate)) {
|
||||||
this@toFirProperty.delegate?.expression?.let { expression ->
|
this@toFirProperty.delegate?.expression?.let { expression ->
|
||||||
expression.toFirExpression("Should have delegate")
|
expression.toFirExpression("Should have delegate")
|
||||||
} ?: buildErrorExpression {
|
} ?: 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
|
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||||
|
|
||||||
class Data {
|
class Data {
|
||||||
|
|||||||
+2
@@ -14,3 +14,5 @@ fun use() {
|
|||||||
A("").<!DEPRECATION!>s<!>
|
A("").<!DEPRECATION!>s<!>
|
||||||
A(42).<!DEPRECATION!>s<!>
|
A(42).<!DEPRECATION!>s<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class DC(@Deprecated("") val a: String)
|
||||||
|
|||||||
@@ -19,6 +19,6 @@ class Iter2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun use() {
|
fun use() {
|
||||||
for (x in Iter()) {}
|
<!DEPRECATION!>for (x in Iter()) {}<!>
|
||||||
for (x in Iter2()) {}
|
<!DEPRECATION, DEPRECATION!>for (x in Iter2()) {}<!>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||||
|
// IGNORE_DIAGNOSTIC_API
|
||||||
|
// IGNORE_REVERSED_RESOLVE
|
||||||
|
// ^KT-61491
|
||||||
|
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
@@ -17,8 +20,8 @@ class PropertyHolder {
|
|||||||
@Deprecated("text")
|
@Deprecated("text")
|
||||||
var name = "String"
|
var name = "String"
|
||||||
|
|
||||||
val valDelegate by Delegate()
|
val valDelegate by <!DEPRECATION!>Delegate<!>()
|
||||||
var varDelegate by Delegate()
|
var varDelegate by <!DEPRECATION, DEPRECATION!>Delegate<!>()
|
||||||
|
|
||||||
public val test1: String = ""
|
public val test1: String = ""
|
||||||
@Deprecated("val-getter") get
|
@Deprecated("val-getter") get
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||||
|
// IGNORE_DIAGNOSTIC_API
|
||||||
|
// IGNORE_REVERSED_RESOLVE
|
||||||
|
// ^KT-61491
|
||||||
|
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
@Deprecated("No")
|
|
||||||
val f: () -> Unit = {}
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
f()
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
@Deprecated("No")
|
@Deprecated("No")
|
||||||
val f: () -> Unit = {}
|
val f: () -> Unit = {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user