diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirDeprecationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirDeprecationChecker.kt index b8ea4d4c32a..ca30a36504c 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirDeprecationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirDeprecationChecker.kt @@ -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( diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index fe67a1cea32..84d40b27565 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -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 -> { diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.kt index e6cc3055424..bd39c3da356 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.kt @@ -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 : C("") + fun use(a: A, b: B, c: C) { A(3) A("") diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.txt index e9463a5d81f..0619f2ac15b 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.txt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.txt @@ -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 +} + diff --git a/compiler/testData/diagnostics/tests/deprecated/genericConstructorUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/genericConstructorUsage.fir.kt deleted file mode 100644 index 51c43c5b11c..00000000000 --- a/compiler/testData/diagnostics/tests/deprecated/genericConstructorUsage.fir.kt +++ /dev/null @@ -1,8 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_EXPRESSION, -UNUSED_PARAMETER - -open class C() { - @Deprecated("") - constructor(p: Int) : this(){} -} - -class D : C(1) diff --git a/compiler/testData/diagnostics/tests/deprecated/genericConstructorUsage.kt b/compiler/testData/diagnostics/tests/deprecated/genericConstructorUsage.kt index 5c084c26a0f..d54ac6cedf1 100644 --- a/compiler/testData/diagnostics/tests/deprecated/genericConstructorUsage.kt +++ b/compiler/testData/diagnostics/tests/deprecated/genericConstructorUsage.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_EXPRESSION, -UNUSED_PARAMETER open class C() { diff --git a/compiler/testData/diagnostics/tests/deprecated/typealiasConstructor.fir.kt b/compiler/testData/diagnostics/tests/deprecated/typealiasConstructor.fir.kt index 4b5948dbfd1..59cd467ddb8 100644 --- a/compiler/testData/diagnostics/tests/deprecated/typealiasConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/deprecated/typealiasConstructor.fir.kt @@ -12,6 +12,6 @@ typealias ArrayListOfDeprecatedClass = ArrayList<DeprecatedClass< class Test1 : DeprecatedClassAlias() -class Test2 : WithDeprecatedCtorAlias() +class Test2 : WithDeprecatedCtorAlias() val test3 = ArrayListOfDeprecatedClass()