[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) { override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) {
if (!allowedSourceKinds.contains(expression.source?.kind)) return 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 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
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( internal fun reportApiStatusIfNeeded(
@@ -1838,7 +1838,7 @@ class DeclarationsConverter(
delegatedSuperTypeRef = first delegatedSuperTypeRef = first
superTypeRefs += first superTypeRefs += first
superTypeCallEntry += second superTypeCallEntry += second
delegateConstructorSource = it.toFirSourceElement(KtFakeSourceElementKind.DelegatingConstructorCall) delegateConstructorSource = it.toFirSourceElement()
index++ index++
} }
DELEGATED_SUPER_TYPE_ENTRY -> { DELEGATED_SUPER_TYPE_ENTRY -> {
@@ -22,10 +22,12 @@ public class B extends A {
} }
// FILE: C.kt // FILE: C.kt
class C @Deprecated("") constructor(s: String) { open class C @Deprecated("") constructor(s: String) {
} }
// FILE: use.kt // FILE: use.kt
class D : <!DEPRECATION!>C<!>("")
fun use(a: A, b: B, c: C) { fun use(a: A, b: B, c: C) {
<!DEPRECATION!>A<!>(3) <!DEPRECATION!>A<!>(3)
A("") A("")
@@ -18,9 +18,17 @@ public open class B : A {
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String 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) @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 equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String 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 // !DIAGNOSTICS: -UNUSED_EXPRESSION, -UNUSED_PARAMETER
open class C<T>() { open class C<T>() {
@@ -12,6 +12,6 @@ typealias ArrayListOfDeprecatedClass = ArrayList<<!DEPRECATION!>DeprecatedClass<
class Test1 : DeprecatedClassAlias() class Test1 : DeprecatedClassAlias()
class Test2 : WithDeprecatedCtorAlias() class Test2 : <!DEPRECATION!>WithDeprecatedCtorAlias<!>()
val test3 = ArrayListOfDeprecatedClass() val test3 = ArrayListOfDeprecatedClass()