[FIR] Report deprecations on deprecated super constructor calls

#KT-57350 Fixed
This commit is contained in:
Kirill Rakhman
2023-04-06 11:39:08 +02:00
committed by Space Team
parent b253a3a47e
commit 206fad4256
7 changed files with 23 additions and 14 deletions
@@ -33,14 +33,20 @@ object FirDeprecationChecker : FirBasicExpressionChecker() {
override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) {
if (!allowedSourceKinds.contains(expression.source?.kind)) return
if (expression is FirAnnotation || expression is FirDelegatedConstructorCall) return //checked by FirDeprecatedTypeChecker
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
reportApiStatusIfNeeded(resolvedReference.source, referencedSymbol, expression, context, reporter)
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
reportApiStatus(resolvedReference.source, referencedSymbol, constructorOnlyDeprecation, reporter, context)
} else {
reportApiStatusIfNeeded(resolvedReference.source, referencedSymbol, expression, context, reporter)
}
}
internal fun reportApiStatusIfNeeded(
@@ -1838,7 +1838,7 @@ class DeclarationsConverter(
delegatedSuperTypeRef = first
superTypeRefs += first
superTypeCallEntry += second
delegateConstructorSource = it.toFirSourceElement(KtFakeSourceElementKind.DelegatingConstructorCall)
delegateConstructorSource = it.toFirSourceElement()
index++
}
DELEGATED_SUPER_TYPE_ENTRY -> {
@@ -22,10 +22,12 @@ public class B extends A {
}
// FILE: C.kt
class C @Deprecated("") constructor(s: String) {
open class C @Deprecated("") constructor(s: String) {
}
// FILE: use.kt
class D : <!DEPRECATION!>C<!>("")
fun use(a: A, b: B, c: C) {
<!DEPRECATION!>A<!>(3)
A("")
@@ -18,9 +18,17 @@ public open class B : A {
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class C {
public open class C {
@kotlin.Deprecated(message = "") public constructor C(/*0*/ s: kotlin.String)
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class D : C {
public constructor D()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,8 +0,0 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION, -UNUSED_PARAMETER
open class C<T>() {
@Deprecated("")
constructor(p: Int) : this(){}
}
class D : C<String>(1)
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_EXPRESSION, -UNUSED_PARAMETER
open class C<T>() {
@@ -12,6 +12,6 @@ typealias ArrayListOfDeprecatedClass = ArrayList<<!DEPRECATION!>DeprecatedClass<
class Test1 : DeprecatedClassAlias()
class Test2 : WithDeprecatedCtorAlias()
class Test2 : <!DEPRECATION!>WithDeprecatedCtorAlias<!>()
val test3 = ArrayListOfDeprecatedClass()