diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirSymbolInfoProvider.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirSymbolInfoProvider.kt index 731b69a730e..9a2261f9c40 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirSymbolInfoProvider.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirSymbolInfoProvider.kt @@ -45,7 +45,6 @@ internal class KtFirSymbolInfoProvider( return when (val firSymbol = symbol.firSymbol) { is FirPropertySymbol -> { firSymbol.getDeprecationForCallSite(apiVersion, AnnotationUseSiteTarget.PROPERTY) - ?: firSymbol.backingFieldSymbol?.getDeprecationForCallSite(apiVersion, AnnotationUseSiteTarget.FIELD) } is FirBackingFieldSymbol -> { firSymbol.getDeprecationForCallSite(apiVersion, AnnotationUseSiteTarget.FIELD) @@ -77,13 +76,21 @@ internal class KtFirSymbolInfoProvider( override fun getGetterDeprecation(symbol: KtPropertySymbol): DeprecationInfo? { require(symbol is KtFirSymbol<*>) - return symbol.firSymbol.getDeprecationForCallSite(apiVersion, AnnotationUseSiteTarget.PROPERTY_GETTER, AnnotationUseSiteTarget.PROPERTY) + return symbol.firSymbol.getDeprecationForCallSite( + apiVersion, + AnnotationUseSiteTarget.PROPERTY_GETTER, + AnnotationUseSiteTarget.PROPERTY, + ) } override fun getSetterDeprecation(symbol: KtPropertySymbol): DeprecationInfo? { require(symbol is KtFirSymbol<*>) - return symbol.firSymbol.getDeprecationForCallSite(apiVersion, AnnotationUseSiteTarget.PROPERTY_SETTER, AnnotationUseSiteTarget.PROPERTY) + return symbol.firSymbol.getDeprecationForCallSite( + apiVersion, + AnnotationUseSiteTarget.PROPERTY_SETTER, + AnnotationUseSiteTarget.PROPERTY, + ) } override fun getJavaGetterName(symbol: KtPropertySymbol): Name { diff --git a/analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.txt b/analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.txt index a26ed0cdfeb..4eb9d8cb671 100644 --- a/analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.txt +++ b/analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.txt @@ -837,7 +837,7 @@ KtKotlinPropertySymbol: symbolKind: LOCAL typeParameters: [] getContainingModule: KtSourceModule "Sources of main" - deprecationStatus: null + deprecationStatus: DeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=false, message=null) callableIdIfNonLocal: /j3 contextReceivers: [] getter: KtPropertyGetterSymbol: diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/FirLazyBodiesCalculator.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/FirLazyBodiesCalculator.kt index 3524ea9c29b..81c52fc7fc6 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/FirLazyBodiesCalculator.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/FirLazyBodiesCalculator.kt @@ -262,7 +262,6 @@ private abstract class FirLazyAnnotationTransformer : FirTransformer = CompilerRequiredAnnotationsHelper.REQUIRED_ANNOTATIONS - .plus(SinceKotlin) .mapTo(mutableSetOf()) { it.shortClassName } private fun canBeCompilerAnnotation(annotationCall: FirAnnotationCall, session: FirSession): Boolean { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index c23cfc2c4e4..580abb64115 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -9500,6 +9500,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.kt"); } + @Test + @TestMetadata("deprecatedConstructorProperty.kt") + public void testDeprecatedConstructorProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedConstructorProperty.kt"); + } + @Test @TestMetadata("deprecatedEnumEntry.kt") public void testDeprecatedEnumEntry() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index d9fa0738e8d..01342f6d2c9 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -9500,6 +9500,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.kt"); } + @Test + @TestMetadata("deprecatedConstructorProperty.kt") + public void testDeprecatedConstructorProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedConstructorProperty.kt"); + } + @Test @TestMetadata("deprecatedEnumEntry.kt") public void testDeprecatedEnumEntry() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 2c5dbb458cb..97dc16e7874 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -9500,6 +9500,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.kt"); } + @Test + @TestMetadata("deprecatedConstructorProperty.kt") + public void testDeprecatedConstructorProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedConstructorProperty.kt"); + } + @Test @TestMetadata("deprecatedEnumEntry.kt") public void testDeprecatedEnumEntry() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 71fdae94b41..ef5374fc97a 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -9506,6 +9506,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.kt"); } + @Test + @TestMetadata("deprecatedConstructorProperty.kt") + public void testDeprecatedConstructorProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedConstructorProperty.kt"); + } + @Test @TestMetadata("deprecatedEnumEntry.kt") public void testDeprecatedEnumEntry() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt index 9cb6f7df00a..f50baad3474 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt @@ -25,7 +25,6 @@ import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.SymbolInternals import org.jetbrains.kotlin.fir.symbols.impl.* -import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl @@ -33,7 +32,6 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability -import org.jetbrains.kotlin.resolve.deprecation.DeprecationInfo import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled @@ -105,13 +103,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() { } if (resolveDeprecations) { - // TODO: drop this condition after KT-57648 - val deprecation = if (symbol is FirClassLikeSymbol<*>) { - symbol.getDeprecation(session, useSiteFile) - } else { - null - } - + val deprecation = symbol.getDeprecation(session, useSiteFile) if (deprecation != null && deprecation.deprecationLevel == DeprecationLevelValue.HIDDEN) { symbolApplicability = minOf(CandidateApplicability.HIDDEN, symbolApplicability) diagnostic = null diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt index 2b5cb31fd94..57807aab87d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt @@ -5,14 +5,12 @@ package org.jetbrains.kotlin.fir.resolve.transformers -import kotlinx.collections.immutable.* +import kotlinx.collections.immutable.toImmutableList +import kotlinx.collections.immutable.toPersistentList import org.jetbrains.kotlin.KtFakeSourceElementKind import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.* -import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.PrivateForInline -import org.jetbrains.kotlin.fir.correspondingProperty -import org.jetbrains.kotlin.fir.copyWithNewSourceKind +import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.isFromVararg import org.jetbrains.kotlin.fir.declarations.utils.isInner @@ -31,7 +29,6 @@ import org.jetbrains.kotlin.fir.scopes.impl.wrapNestedClassifierScopeWithSubstit import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef import org.jetbrains.kotlin.fir.visitors.transformSingle -import org.jetbrains.kotlin.fir.whileAnalysing import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled class FirTypeResolveProcessor( @@ -153,7 +150,6 @@ open class FirTypeResolveTransformer( } } - calculateDeprecations(result) result } } @@ -169,7 +165,6 @@ open class FirTypeResolveTransformer( enumEntry.transformReturnTypeRef(this, data) enumEntry.transformTypeParameters(this, data) enumEntry.transformAnnotations(this, data) - calculateDeprecations(enumEntry) enumEntry } @@ -220,7 +215,6 @@ open class FirTypeResolveTransformer( unboundCyclesInTypeParametersSupertypes(property) property.moveOrDeleteIrrelevantAnnotations() - calculateDeprecations(property) property } } @@ -234,14 +228,12 @@ open class FirTypeResolveTransformer( override fun transformField(field: FirField, data: Any?): FirField = whileAnalysing(session, field) { withScopeCleanup { field.transformReturnTypeRef(this, data).transformAnnotations(this, data) - calculateDeprecations(field) field } } override fun transformBackingField(backingField: FirBackingField, data: Any?): FirStatement = whileAnalysing(session, backingField) { backingField.transformAnnotations(this, data) - calculateDeprecations(backingField) super.transformBackingField(backingField, data) } @@ -254,7 +246,6 @@ open class FirTypeResolveTransformer( addTypeParametersScope(simpleFunction) transformDeclaration(simpleFunction, data).also { unboundCyclesInTypeParametersSupertypes(it as FirTypeParametersOwner) - calculateDeprecations(simpleFunction) } } } as FirSimpleFunction @@ -319,7 +310,6 @@ open class FirTypeResolveTransformer( valueParameter.transformReturnTypeRef(this, data) valueParameter.transformAnnotations(this, data) valueParameter.transformVarargTypeToArrayType() - calculateDeprecations(valueParameter) valueParameter } } @@ -522,11 +512,4 @@ open class FirTypeResolveTransformer( private fun annotationShouldBeMovedToField(allowedTargets: Set): Boolean = (FIELD in allowedTargets || PROPERTY_DELEGATE_FIELD in allowedTargets) && PROPERTY !in allowedTargets - - private fun calculateDeprecations(callableDeclaration: FirCallableDeclaration) { - if (callableDeclaration.deprecationsProvider is UnresolvedDeprecationProvider) { - callableDeclaration.replaceDeprecationsProvider(callableDeclaration.getDeprecationsProvider(session)) - } - } - } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/plugin/AbstractFirSpecificAnnotationResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/plugin/AbstractFirSpecificAnnotationResolveTransformer.kt index 7e407bbed51..7d4330722a3 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/plugin/AbstractFirSpecificAnnotationResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/plugin/AbstractFirSpecificAnnotationResolveTransformer.kt @@ -32,7 +32,10 @@ import org.jetbrains.kotlin.fir.scopes.impl.FirAbstractImportingScope import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirEnumEntrySymbol import org.jetbrains.kotlin.fir.types.* -import org.jetbrains.kotlin.fir.types.builder.* +import org.jetbrains.kotlin.fir.types.builder.buildPlaceholderProjection +import org.jetbrains.kotlin.fir.types.builder.buildStarProjection +import org.jetbrains.kotlin.fir.types.builder.buildTypeProjectionWithVariance +import org.jetbrains.kotlin.fir.types.builder.buildUserTypeRef import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl import org.jetbrains.kotlin.fir.types.impl.FirImplicitUnitTypeRef import org.jetbrains.kotlin.fir.types.impl.FirQualifierPartImpl @@ -41,12 +44,13 @@ import org.jetbrains.kotlin.fir.visitors.FirDefaultTransformer import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.name.StandardClassIds.Annotations.Deprecated import org.jetbrains.kotlin.name.StandardClassIds.Annotations.DeprecatedSinceKotlin +import org.jetbrains.kotlin.name.StandardClassIds.Annotations.Java import org.jetbrains.kotlin.name.StandardClassIds.Annotations.JvmRecord -import org.jetbrains.kotlin.name.StandardClassIds.Annotations.WasExperimental +import org.jetbrains.kotlin.name.StandardClassIds.Annotations.SinceKotlin import org.jetbrains.kotlin.name.StandardClassIds.Annotations.Target +import org.jetbrains.kotlin.name.StandardClassIds.Annotations.WasExperimental import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled /** @@ -56,11 +60,13 @@ object CompilerRequiredAnnotationsHelper { internal val REQUIRED_ANNOTATIONS_WITH_ARGUMENTS: Set = setOf( Deprecated, Target, - StandardClassIds.Annotations.Java.Target, + Java.Target, ) val REQUIRED_ANNOTATIONS: Set = REQUIRED_ANNOTATIONS_WITH_ARGUMENTS + setOf( + Java.Deprecated, DeprecatedSinceKotlin, + SinceKotlin, WasExperimental, JvmRecord, ) @@ -361,12 +367,27 @@ abstract class AbstractFirSpecificAnnotationResolveTransformer( fun calculateDeprecations(classLikeDeclaration: FirClassLikeDeclaration) { if (classLikeDeclaration.deprecationsProvider == UnresolvedDeprecationProvider) { - classLikeDeclaration.replaceDeprecationsProvider( - classLikeDeclaration.getDeprecationsProvider(session) - ) + classLikeDeclaration.replaceDeprecationsProvider(classLikeDeclaration.getDeprecationsProvider(session)) } } + private fun calculateDeprecations(callableDeclaration: FirCallableDeclaration) { + if (callableDeclaration.deprecationsProvider == UnresolvedDeprecationProvider) { + callableDeclaration.replaceDeprecationsProvider(callableDeclaration.getDeprecationsProvider(session)) + } + } + + private fun transformCallableDeclarationForDeprecations( + callableDeclaration: T, + data: Nothing?, + ): FirStatement where T : FirCallableDeclaration, T : FirStatement { + if (!shouldTransformDeclaration(callableDeclaration)) return callableDeclaration + computationSession.recordThatAnnotationsAreResolved(callableDeclaration) + return transformDeclaration(callableDeclaration, data).also { + calculateDeprecations(callableDeclaration) + } as FirStatement + } + lateinit var scopes: List inline fun withFileScopes(file: FirFile, f: () -> T): T { @@ -376,10 +397,43 @@ abstract class AbstractFirSpecificAnnotationResolveTransformer( abstract fun shouldTransformDeclaration(declaration: FirDeclaration): Boolean - override fun transformProperty(property: FirProperty, data: Nothing?): FirProperty { + override fun transformBackingField(backingField: FirBackingField, data: Nothing?): FirStatement { + return transformCallableDeclarationForDeprecations(backingField, data) + } + + override fun transformPropertyAccessor(propertyAccessor: FirPropertyAccessor, data: Nothing?): FirStatement { + return transformCallableDeclarationForDeprecations(propertyAccessor, data) + } + + override fun transformProperty(property: FirProperty, data: Nothing?): FirStatement { if (!shouldTransformDeclaration(property)) return property computationSession.recordThatAnnotationsAreResolved(property) - return transformDeclaration(property, data) as FirProperty + return transformDeclaration(property, data).also { + property.moveJavaDeprecatedAnnotationToBackingField() + + transformChildren(property) { + property.transformSetter(this, data) + property.transformGetter(this, data) + property.transformBackingField(this, data) + } + + calculateDeprecations(property) + } as FirStatement + } + + private fun FirProperty.moveJavaDeprecatedAnnotationToBackingField() { + val annotations = this.annotations + val backingField = this.backingField + if (annotations.isNotEmpty() && backingField != null) { + val (backingFieldAnnotations, propertyAnnotations) = annotations.partition { + it.toAnnotationClassIdSafe(session) == Java.Deprecated + } + + if (backingFieldAnnotations.isNotEmpty()) { + this.replaceAnnotations(propertyAnnotations) + backingField.replaceAnnotations(backingField.annotations + backingFieldAnnotations) + } + } } override fun transformSimpleFunction( @@ -392,6 +446,8 @@ abstract class AbstractFirSpecificAnnotationResolveTransformer( transformChildren(simpleFunction) { simpleFunction.transformValueParameters(this, data) } + + calculateDeprecations(simpleFunction) } as FirSimpleFunction } @@ -405,16 +461,21 @@ abstract class AbstractFirSpecificAnnotationResolveTransformer( transformChildren(constructor) { constructor.transformValueParameters(this, data) } + + calculateDeprecations(constructor) } as FirConstructor } - override fun transformValueParameter( - valueParameter: FirValueParameter, - data: Nothing? - ): FirStatement { - if (!shouldTransformDeclaration(valueParameter)) return valueParameter - computationSession.recordThatAnnotationsAreResolved(valueParameter) - return transformDeclaration(valueParameter, data) as FirStatement + override fun transformEnumEntry(enumEntry: FirEnumEntry, data: Nothing?): FirStatement { + return transformCallableDeclarationForDeprecations(enumEntry, data) + } + + override fun transformField(field: FirField, data: Nothing?): FirStatement { + return transformCallableDeclarationForDeprecations(field, data) + } + + override fun transformValueParameter(valueParameter: FirValueParameter, data: Nothing?): FirStatement { + return transformCallableDeclarationForDeprecations(valueParameter, data) } override fun transformTypeRef(typeRef: FirTypeRef, data: Nothing?): FirTypeRef { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirCallableSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirCallableSymbol.kt index 0a43ea6463a..8f8237c2f38 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirCallableSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirCallableSymbol.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -67,18 +67,10 @@ abstract class FirCallableSymbol : FirBasedSymbol get() = callableId.callableName fun getDeprecation(apiVersion: ApiVersion): DeprecationsPerUseSite? { - if (!canBeDeprecated()) return null - - lazyResolveToPhase(FirResolvePhase.TYPES) + lazyResolveToPhase(FirResolvePhase.COMPILER_REQUIRED_ANNOTATIONS) return fir.deprecationsProvider.getDeprecationsInfo(apiVersion) } - /** - * Checks if symbol can be deprecated by syntax - * @return `true` if symbol might have some deprecation status, or `false` if it's definitely not deprecated - */ - internal open fun canBeDeprecated(): Boolean = true - private fun ensureType(typeRef: FirTypeRef?) { when (typeRef) { null, is FirResolvedTypeRef -> {} diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt index e542882456e..dcd6a0b8926 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.symbols.impl import org.jetbrains.kotlin.fir.FirLabel import org.jetbrains.kotlin.fir.contracts.FirResolvedContractDescription import org.jetbrains.kotlin.fir.declarations.* -import org.jetbrains.kotlin.fir.declarations.utils.isLocal import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference import org.jetbrains.kotlin.fir.references.toResolvedConstructorSymbol @@ -42,12 +41,7 @@ sealed class FirFunctionSymbol( open class FirNamedFunctionSymbol( callableId: CallableId, -) : FirFunctionSymbol(callableId) { - override fun canBeDeprecated(): Boolean { - if (isLocal || callableId.className == null) return annotations.isNotEmpty() - return true - } -} +) : FirFunctionSymbol(callableId) interface FirIntersectionCallableSymbol { val intersections: Collection> @@ -81,10 +75,6 @@ class FirConstructorSymbol( val delegatedConstructorCallIsSuper: Boolean get() = fir.delegatedConstructor?.isSuper ?: false - - override fun canBeDeprecated(): Boolean { - return annotations.isNotEmpty() - } } /** @@ -109,20 +99,12 @@ sealed class FirFunctionWithoutNameSymbol( class FirAnonymousFunctionSymbol : FirFunctionWithoutNameSymbol(Name.identifier("anonymous")) { val label: FirLabel? get() = fir.label - - override fun canBeDeprecated(): Boolean { - return annotations.isNotEmpty() - } } class FirPropertyAccessorSymbol : FirFunctionWithoutNameSymbol(Name.identifier("accessor")) { val isGetter: Boolean get() = fir.isGetter val isSetter: Boolean get() = fir.isSetter val propertySymbol get() = fir.propertySymbol - - override fun canBeDeprecated(): Boolean { - return propertySymbol.canBeDeprecated() - } } class FirErrorFunctionSymbol : FirFunctionWithoutNameSymbol(Name.identifier("error")) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirVariableSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirVariableSymbol.kt index eabf36674f2..3fbaeedf6ce 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirVariableSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirVariableSymbol.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -64,15 +64,6 @@ open class FirPropertySymbol( val isVar: Boolean get() = fir.isVar - - override fun canBeDeprecated(): Boolean { - if (isLocal || callableId.className == null) { - return annotations.isNotEmpty() - || getterSymbol?.annotations?.isNotEmpty() == true - || setterSymbol?.annotations?.isNotEmpty() == true - } - return true - } } class FirIntersectionOverridePropertySymbol( @@ -132,10 +123,6 @@ class FirValueParameterSymbol(name: Name) : FirVariableSymbol val containingFunctionSymbol: FirFunctionSymbol<*> get() = fir.containingFunctionSymbol - - override fun canBeDeprecated(): Boolean { - return false - } } class FirErrorPropertySymbol( diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructorProperty.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructorProperty.kt new file mode 100644 index 00000000000..1cd45150cf4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructorProperty.kt @@ -0,0 +1,16 @@ +// FIR_IDENTICAL +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.kt +class A(@Deprecated("") val s: String) { + + constructor(i: Int) : this(i.toString()) { + + } +} + +// FILE: use.kt +fun use() { + A("").s + A(42).s +} diff --git a/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinImportPriority.fir.kt b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinImportPriority.fir.kt index 4084d1fb3b0..ea5c8e7eba7 100644 --- a/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinImportPriority.fir.kt +++ b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinImportPriority.fir.kt @@ -23,16 +23,16 @@ class A { import p1.* import p2.* -fun test(a: A) { +fun test(a: A) { a.m1() - a.m2() + a.m2() } // FILE: explicitlyImportP1.kt -import p1.A +import p1.A import p2.* -fun test(a: A) { - a.m1() - a.m2() +fun test(a: A) { + a.m1() + a.m2() } diff --git a/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinMultipleClasses.fir.kt b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinMultipleClasses.fir.kt index 949ba2ea4bc..160ab5c96c7 100644 --- a/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinMultipleClasses.fir.kt +++ b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinMultipleClasses.fir.kt @@ -26,12 +26,12 @@ class A(val v3: Unit) // MODULE: m4(m1, m2, m3) // FILE: oneExplicitImportOtherStars.kt import p1.* -import p2.A +import p2.A import p3.* -fun test(a: A) { +fun test(a: A) { a.v1 - a.v2 + a.v2 a.v3 } @@ -40,7 +40,7 @@ import p1.* import p2.* import p3.* -fun test(a: A) { +fun test(a: A) { a.v1 a.v2 a.v3 diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/annotations.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/annotations.fir.kt index 2f81f5e6484..edcc871701e 100644 --- a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/annotations.fir.kt +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/annotations.fir.kt @@ -6,6 +6,6 @@ annotation class Anno1(val s: String) annotation class Anno2 @SinceKotlin("1.1") constructor() -@Anno1("") +@Anno1("") @Anno2 fun t1() {} diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/classesAndConstructors.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/classesAndConstructors.fir.kt index 35991b09006..8a2a2c29567 100644 --- a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/classesAndConstructors.fir.kt +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/classesAndConstructors.fir.kt @@ -11,13 +11,13 @@ class Baz @SinceKotlin("1.1") constructor() @SinceKotlin("1.1") class Quux @SinceKotlin("1.0") constructor() -fun t1(): Foo = Foo() +fun t1(): Foo = Foo() // TODO: do not report API_NOT_AVAILABLE twice -fun t2() = object : Foo() {} +fun t2() = object : Foo() {} fun t3(): Bar? = Bar() fun t4(): Baz = Baz() -fun t5(): Quux = Quux() +fun t5(): Quux = Quux() diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsConstructors.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsConstructors.fir.kt index 2914af2f48d..c1b118c9454 100644 --- a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsConstructors.fir.kt +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsConstructors.fir.kt @@ -3,7 +3,7 @@ @SinceKotlin("1.1") open class C1 -typealias C1_Alias = C1 +typealias C1_Alias = C1 open class C2(val x: Int) { @SinceKotlin("1.1") @@ -12,9 +12,9 @@ open class C2(val x: Int) { typealias C2_Alias = C2 -val test1 = C1_Alias() +val test1 = C1_Alias() val test2 = C2_Alias() -class Test3 : C1_Alias() +class Test3 : C1_Alias() class Test4 : C2_Alias() diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsObjects.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsObjects.fir.kt index a5e80bddcd3..6bf42e28848 100644 --- a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsObjects.fir.kt +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsObjects.fir.kt @@ -5,7 +5,7 @@ object Since_1_1 { val x = 42 } -typealias Since_1_1_Alias = Since_1_1 +typealias Since_1_1_Alias = Since_1_1 val test1 = Since_1_1_Alias -val test2 = Since_1_1_Alias.x \ No newline at end of file +val test2 = Since_1_1_Alias.x diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsTypes.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsTypes.fir.kt index ae3d59b28bf..80146947dfc 100644 --- a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsTypes.fir.kt @@ -5,17 +5,17 @@ class Since_1_1 class C -typealias Since_1_1_Alias = Since_1_1 +typealias Since_1_1_Alias = Since_1_1 -typealias L = List +typealias L = List<Since_1_1> @SinceKotlin("1.1") typealias C_1_1_Alias = C -fun test1(x: Since_1_1_Alias) = x +fun test1(x: Since_1_1_Alias) = x -fun test2(x: C_1_1_Alias) = x +fun test2(x: C_1_1_Alias) = x -fun test3(x: List) = x +fun test3(x: List<C_1_1_Alias>) = x -fun test4(x: L) = x \ No newline at end of file +fun test4(x: L) = x diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesOnImport.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesOnImport.fir.kt index 9c530c9909f..3569c23c07d 100644 --- a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesOnImport.fir.kt +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesOnImport.fir.kt @@ -6,7 +6,7 @@ package a @SinceKotlin("1.1") class Since_1_1 -typealias Since_1_1_Alias = Since_1_1 +typealias Since_1_1_Alias = Since_1_1 @SinceKotlin("1.1") typealias Alias_1_1 = String @@ -14,5 +14,5 @@ typealias Alias_1_1 = String // FILE: b.kt package b -import a.Since_1_1_Alias -import a.Alias_1_1 \ No newline at end of file +import a.Since_1_1_Alias +import a.Alias_1_1 diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 3f2c5254ffe..4a5d9e4f1ff 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -9506,6 +9506,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.kt"); } + @Test + @TestMetadata("deprecatedConstructorProperty.kt") + public void testDeprecatedConstructorProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedConstructorProperty.kt"); + } + @Test @TestMetadata("deprecatedEnumEntry.kt") public void testDeprecatedEnumEntry() throws Exception {