diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonExpressionCheckers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonExpressionCheckers.kt index 828ba156851..87096599629 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonExpressionCheckers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonExpressionCheckers.kt @@ -121,6 +121,7 @@ object CommonExpressionCheckers : ExpressionCheckers() { get() = setOf( FirStandaloneQualifierChecker, FirOptInUsageQualifierChecker, + FirDeprecatedQualifierChecker, ) override val equalityOperatorCallCheckers: Set diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirImportsChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirImportsChecker.kt index 6d417d96240..26bf314a1ce 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirImportsChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirImportsChecker.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration import org.jetbrains.kotlin.fir.analysis.checkers.collectEnumEntries import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirDeprecationChecker import org.jetbrains.kotlin.fir.analysis.checkers.fullyExpandedClass import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors @@ -37,6 +38,7 @@ object FirImportsChecker : FirFileChecker() { checkOperatorRename(import, context, reporter) } } + checkDeprecatedImport(import, context, reporter) } checkConflictingImports(declaration.imports, context, reporter) } @@ -175,4 +177,12 @@ object FirImportsChecker : FirFileChecker() { return hasStatic || !hasIllegal } + + private fun checkDeprecatedImport(import: FirImport, context: CheckerContext, reporter: DiagnosticReporter) { + val importedFqName = import.importedFqName ?: return + if (importedFqName.isRoot || importedFqName.shortName().asString().isEmpty()) return + val classId = (import as? FirResolvedImport)?.resolvedClassId ?: ClassId.topLevel(importedFqName) + val classLike: FirRegularClassSymbol = classId.resolveToClass(context) ?: return + FirDeprecationChecker.reportDeprecationIfNeeded(import.source, classLike, null, context, reporter) + } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirDeprecatedQualifierChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirDeprecatedQualifierChecker.kt new file mode 100644 index 00000000000..0a8e62cecd5 --- /dev/null +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirDeprecatedQualifierChecker.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2021 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. + */ + +package org.jetbrains.kotlin.fir.analysis.checkers.expression + +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier +import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeDeprecated +import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol + +object FirDeprecatedQualifierChecker : FirResolvedQualifierChecker() { + override fun check(expression: FirResolvedQualifier, context: CheckerContext, reporter: DiagnosticReporter) { + expression.nonFatalDiagnostics.filterIsInstance().forEach { diagnostic -> + FirDeprecationChecker.reportDeprecation(diagnostic.source, diagnostic.symbol, diagnostic.deprecation, reporter, context) + } + if (expression.resolvedToCompanionObject) { + val companionSymbol = (expression.symbol as? FirRegularClassSymbol)?.companionObjectSymbol ?: return + FirDeprecationChecker.reportDeprecationIfNeeded(expression.source, companionSymbol, null, context, reporter) + } + } +} \ No newline at end of file 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 e8782d03ce1..378074f10c5 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 @@ -17,9 +17,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn import org.jetbrains.kotlin.fir.declarations.Deprecation import org.jetbrains.kotlin.fir.declarations.DeprecationLevelValue import org.jetbrains.kotlin.fir.declarations.getDeprecation -import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall -import org.jetbrains.kotlin.fir.expressions.FirResolvable -import org.jetbrains.kotlin.fir.expressions.FirStatement +import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol @@ -50,6 +48,16 @@ object FirDeprecationChecker : FirBasicExpressionChecker() { reporter: DiagnosticReporter ) { val deprecation = getWorstDeprecation(callSite, referencedSymbol, context) ?: return + reportDeprecation(source, referencedSymbol, deprecation, reporter, context) + } + + internal fun reportDeprecation( + source: FirSourceElement?, + referencedSymbol: FirBasedSymbol<*>, + deprecation: Deprecation, + reporter: DiagnosticReporter, + context: CheckerContext + ) { val diagnostic = when (deprecation.level) { DeprecationLevelValue.ERROR, DeprecationLevelValue.HIDDEN -> FirErrors.DEPRECATION_ERROR DeprecationLevelValue.WARNING -> FirErrors.DEPRECATION diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/LightTreePositioningStrategies.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/LightTreePositioningStrategies.kt index 51296b0fb67..b8587a5891b 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/LightTreePositioningStrategies.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/LightTreePositioningStrategies.kt @@ -527,36 +527,42 @@ object LightTreePositioningStrategies { endOffset: Int, tree: FlyweightCapableTreeStructure ): List { - if (node.tokenType == KtNodeTypes.CALL_EXPRESSION || node.tokenType == KtNodeTypes.CONSTRUCTOR_DELEGATION_CALL) { - return markElement(tree.referenceExpression(node, locateReferencedName) ?: node, startOffset, endOffset, tree, node) - } - if (node.tokenType == KtNodeTypes.PROPERTY_DELEGATE) { - return markElement(tree.findExpressionDeep(node) ?: node, startOffset, endOffset, tree, node) - } - if (node.tokenType == KtNodeTypes.ANNOTATION_ENTRY) { - return markElement( - tree.findDescendantByType(node, KtNodeTypes.CONSTRUCTOR_CALLEE) ?: node, - startOffset, - endOffset, - tree, - node - ) - } - if (node.tokenType in nodeTypesWithOperation) { - return markElement(tree.operationReference(node) ?: node, startOffset, endOffset, tree, node) - } - if (node.tokenType == KtNodeTypes.TYPE_REFERENCE) { - val nodeToMark = - tree.findChildByType(node, KtNodeTypes.NULLABLE_TYPE) - ?.let { tree.findChildByType(it, KtNodeTypes.USER_TYPE) } - ?: node - return markElement(nodeToMark, startOffset, endOffset, tree, node) - } - if (node.tokenType != KtNodeTypes.DOT_QUALIFIED_EXPRESSION && - node.tokenType != KtNodeTypes.SAFE_ACCESS_EXPRESSION && - node.tokenType != KtNodeTypes.CALLABLE_REFERENCE_EXPRESSION - ) { - return super.mark(node, startOffset, endOffset, tree) + when { + node.tokenType == KtNodeTypes.CALL_EXPRESSION || node.tokenType == KtNodeTypes.CONSTRUCTOR_DELEGATION_CALL -> { + return markElement(tree.referenceExpression(node, locateReferencedName) ?: node, startOffset, endOffset, tree, node) + } + node.tokenType == KtNodeTypes.PROPERTY_DELEGATE -> { + return markElement(tree.findExpressionDeep(node) ?: node, startOffset, endOffset, tree, node) + } + node.tokenType == KtNodeTypes.ANNOTATION_ENTRY -> { + return markElement( + tree.findDescendantByType(node, KtNodeTypes.CONSTRUCTOR_CALLEE) ?: node, + startOffset, + endOffset, + tree, + node + ) + } + node.tokenType in nodeTypesWithOperation -> { + return markElement(tree.operationReference(node) ?: node, startOffset, endOffset, tree, node) + } + node.tokenType == KtNodeTypes.TYPE_REFERENCE -> { + val nodeToMark = + tree.findChildByType(node, KtNodeTypes.NULLABLE_TYPE) + ?.let { tree.findChildByType(it, KtNodeTypes.USER_TYPE) } + ?: node + return markElement(nodeToMark, startOffset, endOffset, tree, node) + } + node.tokenType == KtNodeTypes.IMPORT_DIRECTIVE -> { + val nodeToMark = tree.findChildByType(node, KtStubElementTypes.INSIDE_DIRECTIVE_EXPRESSIONS) ?: node + return markElement(nodeToMark, startOffset, endOffset, tree, node) + } + node.tokenType != KtNodeTypes.DOT_QUALIFIED_EXPRESSION && + node.tokenType != KtNodeTypes.SAFE_ACCESS_EXPRESSION && + node.tokenType != KtNodeTypes.CALLABLE_REFERENCE_EXPRESSION + -> { + return super.mark(node, startOffset, endOffset, tree) + } } val selector = tree.selector(node) if (selector != null) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt index 1d868388dc4..7acf8e17e53 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt @@ -254,7 +254,12 @@ class FirCallResolver( referencedSymbol, nameReference.source, qualifiedAccess.typeArguments, - diagnostic + diagnostic, + nonFatalDiagnostics = extractNonFatalDiagnostics( + nameReference.source, + qualifiedAccess.explicitReceiver, + referencedSymbol + ) ) } referencedSymbol is FirTypeParameterSymbol && referencedSymbol.fir.isReified -> { @@ -276,6 +281,17 @@ class FirCallResolver( return resultExpression } + private fun extractNonFatalDiagnostics( + source: FirSourceElement?, + explicitReceiver: FirExpression?, + symbol: FirClassLikeSymbol<*> + ): List { + val prevDiagnostics = (explicitReceiver as? FirResolvedQualifier)?.nonFatalDiagnostics ?: emptyList() + return symbol.fir.deprecation?.forUseSite()?.let { + prevDiagnostics + ConeDeprecated(source, symbol, it) + } ?: prevDiagnostics + } + fun resolveCallableReference( constraintSystemBuilder: ConstraintSystemBuilder, resolvedCallableReferenceAtom: ResolvedCallableReferenceAtom, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt index 323b9da5ded..6508521c20f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt @@ -114,7 +114,8 @@ fun BodyResolveComponents.buildResolvedQualifierForClass( sourceElement: FirSourceElement? = null, // TODO: Clarify if we actually need type arguments for qualifier? typeArgumentsForQualifier: List = emptyList(), - diagnostic: ConeDiagnostic? = null + diagnostic: ConeDiagnostic? = null, + nonFatalDiagnostics: List = emptyList() ): FirResolvedQualifier { val classId = regularClass.classId @@ -130,6 +131,7 @@ fun BodyResolveComponents.buildResolvedQualifierForClass( relativeClassFqName = classId.relativeClassName typeArguments.addAll(typeArgumentsForQualifier) symbol = regularClass + this.nonFatalDiagnostics.addAll(nonFatalDiagnostics) }.build().apply { resultType = if (classId.isLocal) { typeForQualifierByDeclaration(regularClass.fir, resultType, session) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt index 1d0749cef72..82deed64986 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.diagnostics import kotlinx.collections.immutable.ImmutableList import org.jetbrains.kotlin.fir.FirSourceElement +import org.jetbrains.kotlin.fir.declarations.Deprecation import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic @@ -147,6 +148,10 @@ class ConeUnsupportedDynamicType() : ConeDiagnostic() { override val reason: String get() = "Dynamic types are not supported in this context" } +class ConeDeprecated(val source: FirSourceElement?, val symbol: FirBasedSymbol<*>, val deprecation: Deprecation) : ConeDiagnostic() { + override val reason: String get() = "Deprecated: ${deprecation.message}" +} + private fun describeSymbol(symbol: FirBasedSymbol<*>): String { return when (symbol) { is FirClassLikeSymbol<*> -> symbol.classId.asString() diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirErrorResolvedQualifier.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirErrorResolvedQualifier.kt index e934a228186..7d87b87ba17 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirErrorResolvedQualifier.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirErrorResolvedQualifier.kt @@ -31,6 +31,7 @@ abstract class FirErrorResolvedQualifier : FirResolvedQualifier(), FirDiagnostic abstract override val symbol: FirClassLikeSymbol<*>? abstract override val isNullableLHSForCallableReference: Boolean abstract override val resolvedToCompanionObject: Boolean + abstract override val nonFatalDiagnostics: List abstract override val typeArguments: List abstract override val diagnostic: ConeDiagnostic diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirResolvedQualifier.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirResolvedQualifier.kt index 181b999eaad..fe81702e9a1 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirResolvedQualifier.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirResolvedQualifier.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.expressions import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSourceElement +import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol import org.jetbrains.kotlin.fir.types.FirTypeProjection import org.jetbrains.kotlin.fir.types.FirTypeRef @@ -29,6 +30,7 @@ abstract class FirResolvedQualifier : FirExpression() { abstract val symbol: FirClassLikeSymbol<*>? abstract val isNullableLHSForCallableReference: Boolean abstract val resolvedToCompanionObject: Boolean + abstract val nonFatalDiagnostics: List abstract val typeArguments: List override fun accept(visitor: FirVisitor, data: D): R = visitor.visitResolvedQualifier(this, data) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirAbstractResolvedQualifierBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirAbstractResolvedQualifierBuilder.kt index e02bbe76bdc..dec269b9b29 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirAbstractResolvedQualifierBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirAbstractResolvedQualifierBuilder.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.expressions.builder import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.builder.FirBuilderDsl +import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol @@ -32,6 +33,7 @@ interface FirAbstractResolvedQualifierBuilder { abstract var symbol: FirClassLikeSymbol<*>? abstract var isNullableLHSForCallableReference: Boolean abstract var resolvedToCompanionObject: Boolean + abstract val nonFatalDiagnostics: MutableList abstract val typeArguments: MutableList fun build(): FirResolvedQualifier diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorResolvedQualifierBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorResolvedQualifierBuilder.kt index a9285208fd6..164bd8a16af 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorResolvedQualifierBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorResolvedQualifierBuilder.kt @@ -37,6 +37,7 @@ class FirErrorResolvedQualifierBuilder : FirAbstractResolvedQualifierBuilder, Fi override var classId: ClassId? = null override var symbol: FirClassLikeSymbol<*>? = null override var isNullableLHSForCallableReference: Boolean = false + override val nonFatalDiagnostics: MutableList = mutableListOf() override val typeArguments: MutableList = mutableListOf() lateinit var diagnostic: ConeDiagnostic @@ -49,6 +50,7 @@ class FirErrorResolvedQualifierBuilder : FirAbstractResolvedQualifierBuilder, Fi classId, symbol, isNullableLHSForCallableReference, + nonFatalDiagnostics, typeArguments, diagnostic, ) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirResolvedQualifierBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirResolvedQualifierBuilder.kt index 4b3d4e1c1c1..27c687e3107 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirResolvedQualifierBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirResolvedQualifierBuilder.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder import org.jetbrains.kotlin.fir.builder.FirBuilderDsl import org.jetbrains.kotlin.fir.declarations.FirRegularClass +import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier import org.jetbrains.kotlin.fir.expressions.builder.FirAbstractResolvedQualifierBuilder @@ -37,6 +38,7 @@ class FirResolvedQualifierBuilder : FirAbstractResolvedQualifierBuilder, FirAnno override var relativeClassFqName: FqName? = null override var symbol: FirClassLikeSymbol<*>? = null override var isNullableLHSForCallableReference: Boolean = false + override val nonFatalDiagnostics: MutableList = mutableListOf() override val typeArguments: MutableList = mutableListOf() override fun build(): FirResolvedQualifier { @@ -48,6 +50,7 @@ class FirResolvedQualifierBuilder : FirAbstractResolvedQualifierBuilder, FirAnno relativeClassFqName, symbol, isNullableLHSForCallableReference, + nonFatalDiagnostics, typeArguments, ) } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorResolvedQualifierImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorResolvedQualifierImpl.kt index c61d6e97d99..b5223caa4f3 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorResolvedQualifierImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorResolvedQualifierImpl.kt @@ -30,6 +30,7 @@ internal class FirErrorResolvedQualifierImpl( override val classId: ClassId?, override val symbol: FirClassLikeSymbol<*>?, override var isNullableLHSForCallableReference: Boolean, + override val nonFatalDiagnostics: MutableList, override val typeArguments: MutableList, override val diagnostic: ConeDiagnostic, ) : FirErrorResolvedQualifier() { diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirResolvedQualifierImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirResolvedQualifierImpl.kt index 4e623faa6a7..6206fa87cf8 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirResolvedQualifierImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirResolvedQualifierImpl.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.expressions.impl import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.declarations.FirRegularClass +import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol @@ -29,6 +30,7 @@ internal class FirResolvedQualifierImpl( override var relativeClassFqName: FqName?, override val symbol: FirClassLikeSymbol<*>?, override var isNullableLHSForCallableReference: Boolean, + override val nonFatalDiagnostics: MutableList, override val typeArguments: MutableList, ) : FirResolvedQualifier() { override val classId: ClassId? get() = relativeClassFqName?.let { diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index 83c3826d821..1c3a97c0f5f 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -503,6 +503,7 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild +field("symbol", classLikeSymbolType, nullable = true) +booleanField("isNullableLHSForCallableReference", withReplace = true) +booleanField("resolvedToCompanionObject", withReplace = true) + +fieldList("nonFatalDiagnostics", coneDiagnosticType) +typeArguments.withTransform() } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt index f9937c1d6fa..d8e96a3df69 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt @@ -978,6 +978,7 @@ object PositioningStrategies { is KtWhenConditionInRange -> element.operationReference is KtAnnotationEntry -> element.calleeExpression ?: element is KtTypeReference -> (element.typeElement as? KtNullableType)?.innerType ?: element + is KtImportDirective -> element.importedReference ?: element else -> element } while (locateReferencedName && result is KtParenthesizedExpression) { diff --git a/compiler/testData/diagnostics/tests/deprecated/companionObjectUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/companionObjectUsage.fir.kt deleted file mode 100644 index b348132c308..00000000000 --- a/compiler/testData/diagnostics/tests/deprecated/companionObjectUsage.fir.kt +++ /dev/null @@ -1,32 +0,0 @@ -class Another { - @Deprecated("Object") - companion object { - fun use() {} - const val USE = 42 - } -} - -fun first() { - Another.use() - Another.Companion.USE - Another.USE -} - -fun useCompanion() { - val d = Another - val x = Another.Companion - Another.Companion.use() - Another.use() -} - -@Deprecated("Some") -class Some { - companion object { - fun use() {} - } -} - -fun some() { - Some.use() - Some.Companion.use() -} diff --git a/compiler/testData/diagnostics/tests/deprecated/companionObjectUsage.kt b/compiler/testData/diagnostics/tests/deprecated/companionObjectUsage.kt index c9f6cd54537..7c900ec45b0 100644 --- a/compiler/testData/diagnostics/tests/deprecated/companionObjectUsage.kt +++ b/compiler/testData/diagnostics/tests/deprecated/companionObjectUsage.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class Another { @Deprecated("Object") companion object { diff --git a/compiler/testData/diagnostics/tests/deprecated/importJavaSamInterface.fir.kt b/compiler/testData/diagnostics/tests/deprecated/importJavaSamInterface.fir.kt index 8b28ed7ebfd..b50ca5bda9d 100644 --- a/compiler/testData/diagnostics/tests/deprecated/importJavaSamInterface.fir.kt +++ b/compiler/testData/diagnostics/tests/deprecated/importJavaSamInterface.fir.kt @@ -10,4 +10,4 @@ public interface J { // FILE: K.kt -import test.J +import test.J diff --git a/compiler/testData/diagnostics/tests/deprecated/imports.fir.kt b/compiler/testData/diagnostics/tests/deprecated/imports.fir.kt deleted file mode 100644 index e575820646a..00000000000 --- a/compiler/testData/diagnostics/tests/deprecated/imports.fir.kt +++ /dev/null @@ -1,8 +0,0 @@ -import C as C2 - -@Deprecated("obsolete") -class C { - fun use() {} -} - -fun useAlias(c : C2) { c.use() } diff --git a/compiler/testData/diagnostics/tests/deprecated/imports.kt b/compiler/testData/diagnostics/tests/deprecated/imports.kt index 3796ae10e20..cfaee1810ac 100644 --- a/compiler/testData/diagnostics/tests/deprecated/imports.kt +++ b/compiler/testData/diagnostics/tests/deprecated/imports.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL import C as C2 @Deprecated("obsolete") diff --git a/compiler/testData/diagnostics/tests/deprecated/nestedTypesUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/nestedTypesUsage.fir.kt deleted file mode 100644 index 6309291069a..00000000000 --- a/compiler/testData/diagnostics/tests/deprecated/nestedTypesUsage.fir.kt +++ /dev/null @@ -1,18 +0,0 @@ -class TopLevel { - @Deprecated("Nested") - class Nested { - companion object { - fun use() {} - - class CompanionNested2 - } - - class Nested2 - } -} - -fun useNested() { - val d = TopLevel.Nested.use() - TopLevel.Nested.Nested2() - TopLevel.Nested.CompanionNested2() -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/nestedTypesUsage.kt b/compiler/testData/diagnostics/tests/deprecated/nestedTypesUsage.kt index d3b9c5612f6..9b7f3242a6a 100644 --- a/compiler/testData/diagnostics/tests/deprecated/nestedTypesUsage.kt +++ b/compiler/testData/diagnostics/tests/deprecated/nestedTypesUsage.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class TopLevel { @Deprecated("Nested") class Nested { diff --git a/compiler/testData/diagnostics/tests/deprecated/objectUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/objectUsage.fir.kt deleted file mode 100644 index 5cfe5dab560..00000000000 --- a/compiler/testData/diagnostics/tests/deprecated/objectUsage.fir.kt +++ /dev/null @@ -1,9 +0,0 @@ -@Deprecated("Object") -object Obsolete { - fun use() {} -} - -fun useObject() { - Obsolete.use() - val x = Obsolete -} diff --git a/compiler/testData/diagnostics/tests/deprecated/objectUsage.kt b/compiler/testData/diagnostics/tests/deprecated/objectUsage.kt index 1a9d59c6b3f..48663226082 100644 --- a/compiler/testData/diagnostics/tests/deprecated/objectUsage.kt +++ b/compiler/testData/diagnostics/tests/deprecated/objectUsage.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL @Deprecated("Object") object Obsolete { fun use() {} diff --git a/compiler/testData/diagnostics/tests/deprecated/typealiasCompanionObject.fir.kt b/compiler/testData/diagnostics/tests/deprecated/typealiasCompanionObject.fir.kt deleted file mode 100644 index 8ef5f484f00..00000000000 --- a/compiler/testData/diagnostics/tests/deprecated/typealiasCompanionObject.fir.kt +++ /dev/null @@ -1,12 +0,0 @@ -class Relevant { - companion object { - val value = "" - } -} - -@Deprecated("Use Relevant") -typealias Obsolete = Relevant - -fun test1() = Obsolete -fun test2() = Obsolete.value -fun test3() = Obsolete.toString() diff --git a/compiler/testData/diagnostics/tests/deprecated/typealiasCompanionObject.kt b/compiler/testData/diagnostics/tests/deprecated/typealiasCompanionObject.kt index 823a2bdaa06..f1fdbaae7e8 100644 --- a/compiler/testData/diagnostics/tests/deprecated/typealiasCompanionObject.kt +++ b/compiler/testData/diagnostics/tests/deprecated/typealiasCompanionObject.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class Relevant { companion object { val value = "" diff --git a/compiler/testData/diagnostics/tests/deprecated/typealiasUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/typealiasUsage.fir.kt index 111d8f7846a..9aa8d3c4009 100644 --- a/compiler/testData/diagnostics/tests/deprecated/typealiasUsage.fir.kt +++ b/compiler/testData/diagnostics/tests/deprecated/typealiasUsage.fir.kt @@ -16,7 +16,7 @@ fun test1a(x: List<Obsolete>) = x val test2 = Obsolete() -val test3 = Obsolete +val test3 = Obsolete class Test4: Obsolete() class Test4a: IObsolete diff --git a/compiler/testData/diagnostics/tests/deprecated/unusedImport.fir.kt b/compiler/testData/diagnostics/tests/deprecated/unusedImport.fir.kt index 67783b81d14..4a8f6991a01 100644 --- a/compiler/testData/diagnostics/tests/deprecated/unusedImport.fir.kt +++ b/compiler/testData/diagnostics/tests/deprecated/unusedImport.fir.kt @@ -7,4 +7,4 @@ interface A // FILE: B.kt -import test.A +import test.A diff --git a/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenImportPriority.fir.kt b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenImportPriority.fir.kt index a1b1cbfe9de..366b26b26b6 100644 --- a/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenImportPriority.fir.kt +++ b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenImportPriority.fir.kt @@ -28,7 +28,7 @@ fun test(a: A) { } // FILE: explicitlyImportP1.kt -import p1.A +import p1.A import p2.* fun test(a: A) { diff --git a/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenMultipleClasses.fir.kt b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenMultipleClasses.fir.kt index 2302479978c..0b117e87baf 100644 --- a/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenMultipleClasses.fir.kt +++ b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenMultipleClasses.fir.kt @@ -25,7 +25,7 @@ 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) {