From b47cc86c57431c51291eb9bd7844868c16ed571f Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 15 Feb 2022 13:09:13 +0300 Subject: [PATCH] [FIR] Fix incorrect context usages with `withSuppressedDiagnostics` call --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++ ...irOldFrontendDiagnosticsTestGenerated.java | 6 +++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++ .../FirRepeatableAnnotationChecker.kt | 4 +- .../analysis/checkers/FirAnnotationHelpers.kt | 2 +- .../FirInconsistentTypeParameterHelpers.kt | 6 +-- .../declaration/FirAnnotationChecker.kt | 4 +- .../declaration/FirMemberPropertiesChecker.kt | 18 ++++----- ...ethodOfAnyImplementedInInterfaceChecker.kt | 2 +- .../FirOptInMarkedDeclarationChecker.kt | 10 ++--- .../declaration/FirOverrideChecker.kt | 2 +- .../FirPropertyAccessorsTypesChecker.kt | 38 +++++++++---------- .../declaration/FirSupertypesChecker.kt | 34 ++++++++--------- .../FirTopLevelPropertiesChecker.kt | 6 +-- .../FirExpressionAnnotationChecker.kt | 8 ++-- .../expression/FirLoopConditionChecker.kt | 2 +- .../expression/FirWhenConditionChecker.kt | 4 +- .../type/FirOptInUsageTypeRefChecker.kt | 2 +- .../checkers/type/FirTypeAnnotationChecker.kt | 2 +- .../oneWarning/suppressOnDeclarationItself.kt | 7 ++++ .../suppressOnDeclarationItself.txt | 9 +++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++ .../diagnostics/FirParcelizeClassChecker.kt | 2 +- 23 files changed, 113 insertions(+), 73 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/suppressOnDeclarationItself.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/suppressOnDeclarationItself.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index d85f0b3a140..c1cb5dac143 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -30312,6 +30312,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag public void testOnTypeParameter() throws Exception { runTest("compiler/testData/diagnostics/tests/suppress/oneWarning/onTypeParameter.kt"); } + + @Test + @TestMetadata("suppressOnDeclarationItself.kt") + public void testSuppressOnDeclarationItself() throws Exception { + runTest("compiler/testData/diagnostics/tests/suppress/oneWarning/suppressOnDeclarationItself.kt"); + } } } diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 66c610ab385..37c5283dc54 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -30312,6 +30312,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti public void testOnTypeParameter() throws Exception { runTest("compiler/testData/diagnostics/tests/suppress/oneWarning/onTypeParameter.kt"); } + + @Test + @TestMetadata("suppressOnDeclarationItself.kt") + public void testSuppressOnDeclarationItself() throws Exception { + runTest("compiler/testData/diagnostics/tests/suppress/oneWarning/suppressOnDeclarationItself.kt"); + } } } diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index c80b7050b72..8052b315b42 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -30312,6 +30312,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac public void testOnTypeParameter() throws Exception { runTest("compiler/testData/diagnostics/tests/suppress/oneWarning/onTypeParameter.kt"); } + + @Test + @TestMetadata("suppressOnDeclarationItself.kt") + public void testSuppressOnDeclarationItself() throws Exception { + runTest("compiler/testData/diagnostics/tests/suppress/oneWarning/suppressOnDeclarationItself.kt"); + } } } diff --git a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirRepeatableAnnotationChecker.kt b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirRepeatableAnnotationChecker.kt index fee3c58a854..514022e6343 100644 --- a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirRepeatableAnnotationChecker.kt +++ b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirRepeatableAnnotationChecker.kt @@ -88,13 +88,13 @@ object FirRepeatableAnnotationChecker : FirBasicDeclarationChecker() { val javaRepeatable = annotations.find { it.classId == StandardClassIds.Annotations.Java.Repeatable } if (javaRepeatable != null) { withSuppressedDiagnostics(javaRepeatable, context) { - checkJavaRepeatableAnnotationDeclaration(javaRepeatable, declaration, context, reporter) + checkJavaRepeatableAnnotationDeclaration(javaRepeatable, declaration, it, reporter) } } else { val kotlinRepeatable = annotations.find { it.classId == StandardClassIds.Annotations.Repeatable } if (kotlinRepeatable != null) { withSuppressedDiagnostics(kotlinRepeatable, context) { - checkKotlinRepeatableAnnotationDeclaration(kotlinRepeatable, declaration, context, reporter) + checkKotlinRepeatableAnnotationDeclaration(kotlinRepeatable, declaration, it, reporter) } } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirAnnotationHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirAnnotationHelpers.kt index 79d3f433fc2..e94d9f61f17 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirAnnotationHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirAnnotationHelpers.kt @@ -185,7 +185,7 @@ fun checkRepeatedAnnotation( val existingTargetsForAnnotation = annotationsMap.getOrPut(annotation.annotationTypeRef.coneType) { arrayListOf() } withSuppressedDiagnostics(annotation, context) { - checkRepeatedAnnotation(useSiteTarget, existingTargetsForAnnotation, annotation, context, reporter) + checkRepeatedAnnotation(useSiteTarget, existingTargetsForAnnotation, annotation, it, reporter) } existingTargetsForAnnotation.add(useSiteTarget) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirInconsistentTypeParameterHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirInconsistentTypeParameterHelpers.kt index a6211b32d17..9bc2ee45856 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirInconsistentTypeParameterHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirInconsistentTypeParameterHelpers.kt @@ -62,7 +62,7 @@ private fun buildDeepSubstitutionMultimap( val session = context.session val typeContext = session.typeContext - fun fillInDeepSubstitutor(typeArguments: Array?, classSymbol: FirRegularClassSymbol) { + fun fillInDeepSubstitutor(typeArguments: Array?, classSymbol: FirRegularClassSymbol, context: CheckerContext) { if (typeArguments != null) { val typeParameterSymbols = classSymbol.typeParameterSymbols val count = minOf(typeArguments.size, typeParameterSymbols.size) @@ -106,14 +106,14 @@ private fun buildDeepSubstitutionMultimap( val superClassSymbol = fullyExpandedType.toRegularClassSymbol(session) withSuppressedDiagnostics(superTypeRef, context) { if (!fullyExpandedType.isEnum && superClassSymbol != null) { - fillInDeepSubstitutor(fullyExpandedType.typeArguments, superClassSymbol) + fillInDeepSubstitutor(fullyExpandedType.typeArguments, superClassSymbol, it) } } } } for (firTypeRefClass in firTypeRefClasses) { - fillInDeepSubstitutor(firTypeRefClass.first?.coneType?.fullyExpandedType(session)?.typeArguments, firTypeRefClass.second) + fillInDeepSubstitutor(firTypeRefClass.first?.coneType?.fullyExpandedType(session)?.typeArguments, firTypeRefClass.second, context) } return result } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAnnotationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAnnotationChecker.kt index af198a6e990..14c5362a72a 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAnnotationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAnnotationChecker.kt @@ -53,12 +53,12 @@ object FirAnnotationChecker : FirBasicDeclarationChecker() { } withSuppressedDiagnostics(annotation, context) { - checkAnnotationTarget(declaration, annotation, context, reporter) + checkAnnotationTarget(declaration, annotation, it, reporter) } } if (deprecatedSinceKotlin != null) { withSuppressedDiagnostics(deprecatedSinceKotlin, context) { - checkDeprecatedCalls(deprecatedSinceKotlin, deprecated, context, reporter) + checkDeprecatedCalls(deprecatedSinceKotlin, deprecated, it, reporter) } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirMemberPropertiesChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirMemberPropertiesChecker.kt index f6249ec90be..91b1dc91c76 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirMemberPropertiesChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirMemberPropertiesChecker.kt @@ -169,17 +169,17 @@ object FirMemberPropertiesChecker : FirClassChecker() { // So, our source of truth should be the full modifier list retrieved from the source. val modifierList = property.source.getModifierList() - withSuppressedDiagnostics(property, context) { + withSuppressedDiagnostics(property, context) { ctx -> checkPropertyInitializer( containingDeclaration, property, modifierList, isInitialized, reporter, - context, + ctx, reachable ) - checkExpectDeclarationVisibilityAndBody(property, source, reporter, context) + checkExpectDeclarationVisibilityAndBody(property, source, reporter, ctx) val hasAbstractModifier = KtTokens.ABSTRACT_KEYWORD in modifierList val isAbstract = property.isAbstract || hasAbstractModifier @@ -189,7 +189,7 @@ object FirMemberPropertiesChecker : FirClassChecker() { (property.getter == null || property.getter is FirDefaultPropertyAccessor) ) { property.source?.let { - reporter.reportOn(it, FirErrors.PRIVATE_PROPERTY_IN_INTERFACE, context) + reporter.reportOn(it, FirErrors.PRIVATE_PROPERTY_IN_INTERFACE, ctx) } } @@ -201,16 +201,16 @@ object FirMemberPropertiesChecker : FirClassChecker() { FirErrors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, property.symbol, containingDeclaration.symbol, - context + ctx ) return } } property.initializer?.source?.let { - reporter.reportOn(it, FirErrors.ABSTRACT_PROPERTY_WITH_INITIALIZER, context) + reporter.reportOn(it, FirErrors.ABSTRACT_PROPERTY_WITH_INITIALIZER, ctx) } property.delegate?.source?.let { - reporter.reportOn(it, FirErrors.ABSTRACT_DELEGATED_PROPERTY, context) + reporter.reportOn(it, FirErrors.ABSTRACT_DELEGATED_PROPERTY, ctx) } } @@ -219,10 +219,10 @@ object FirMemberPropertiesChecker : FirClassChecker() { containingDeclaration.isInterface && !hasAbstractModifier && property.isAbstract && - !isInsideExpectClass(containingDeclaration, context) + !isInsideExpectClass(containingDeclaration, ctx) ) { property.source?.let { - reporter.reportOn(it, FirErrors.REDUNDANT_OPEN_IN_INTERFACE, context) + reporter.reportOn(it, FirErrors.REDUNDANT_OPEN_IN_INTERFACE, ctx) } } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirMethodOfAnyImplementedInInterfaceChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirMethodOfAnyImplementedInInterfaceChecker.kt index c72501ec5b0..6aad3517398 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirMethodOfAnyImplementedInInterfaceChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirMethodOfAnyImplementedInInterfaceChecker.kt @@ -50,7 +50,7 @@ object FirMethodOfAnyImplementedInInterfaceChecker : FirRegularClassChecker(), F if (methodOfAny) { withSuppressedDiagnostics(function, context) { - reporter.reportOn(function.source, FirErrors.METHOD_OF_ANY_IMPLEMENTED_IN_INTERFACE, context) + reporter.reportOn(function.source, FirErrors.METHOD_OF_ANY_IMPLEMENTED_IN_INTERFACE, it) } } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOptInMarkedDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOptInMarkedDeclarationChecker.kt index 7deb515360a..97ee6588663 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOptInMarkedDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOptInMarkedDeclarationChecker.kt @@ -23,22 +23,22 @@ object FirOptInMarkedDeclarationChecker : FirBasicDeclarationChecker() { override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) { for (annotation in declaration.annotations) { val annotationClass = annotation.getAnnotationClassForOptInMarker(context.session) ?: continue - withSuppressedDiagnostics(annotation, context) { + withSuppressedDiagnostics(annotation, context) { ctx -> val useSiteTarget = annotation.useSiteTarget if ((declaration is FirPropertyAccessor && declaration.isGetter) || useSiteTarget == PROPERTY_GETTER) { - reporter.reportOn(annotation.source, FirErrors.OPT_IN_MARKER_ON_WRONG_TARGET, "getter", context) + reporter.reportOn(annotation.source, FirErrors.OPT_IN_MARKER_ON_WRONG_TARGET, "getter", ctx) } if (useSiteTarget == SETTER_PARAMETER || (useSiteTarget != PROPERTY && useSiteTarget != PROPERTY_SETTER && declaration is FirValueParameter && KotlinTarget.VALUE_PARAMETER in annotationClass.getAllowedAnnotationTargets()) ) { - reporter.reportOn(annotation.source, FirErrors.OPT_IN_MARKER_ON_WRONG_TARGET, "parameter", context) + reporter.reportOn(annotation.source, FirErrors.OPT_IN_MARKER_ON_WRONG_TARGET, "parameter", ctx) } if (declaration is FirProperty && declaration.isLocal) { - reporter.reportOn(annotation.source, FirErrors.OPT_IN_MARKER_ON_WRONG_TARGET, "variable", context) + reporter.reportOn(annotation.source, FirErrors.OPT_IN_MARKER_ON_WRONG_TARGET, "variable", ctx) } if (useSiteTarget == FIELD || useSiteTarget == PROPERTY_DELEGATE_FIELD) { - reporter.reportOn(annotation.source, FirErrors.OPT_IN_MARKER_ON_WRONG_TARGET, "field", context) + reporter.reportOn(annotation.source, FirErrors.OPT_IN_MARKER_ON_WRONG_TARGET, "field", ctx) } } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt index 74c43710ad1..130180c41af 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt @@ -58,7 +58,7 @@ object FirOverrideChecker : FirClassChecker() { if (it is FirSimpleFunction || it is FirProperty) { val callable = it as FirCallableDeclaration withSuppressedDiagnostics(callable, context) { - checkMember(callable.symbol, declaration, reporter, typeCheckerState, firTypeScope, context) + checkMember(callable.symbol, declaration, reporter, typeCheckerState, firTypeScope, it) } } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyAccessorsTypesChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyAccessorsTypesChecker.kt index 8d6a55eeedf..3df40564d03 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyAccessorsTypesChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyAccessorsTypesChecker.kt @@ -34,14 +34,14 @@ object FirPropertyAccessorsTypesChecker : FirPropertyChecker() { val getter = property.getter ?: return val propertyType = property.returnTypeRef.coneType - withSuppressedDiagnostics(getter, context) { - checkAccessorForDelegatedProperty(property, getter, context, reporter) + withSuppressedDiagnostics(getter, context) { ctx -> + checkAccessorForDelegatedProperty(property, getter, ctx, reporter) if (getter.visibility != property.visibility) { - reporter.reportOn(getter.source, FirErrors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, context) + reporter.reportOn(getter.source, FirErrors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, ctx) } if (property.symbol.callableId.classId != null && getter.body != null && property.delegate == null) { - if (isLegallyAbstract(property, context)) { - reporter.reportOn(getter.source, FirErrors.ABSTRACT_PROPERTY_WITH_GETTER, context) + if (isLegallyAbstract(property, ctx)) { + reporter.reportOn(getter.source, FirErrors.ABSTRACT_PROPERTY_WITH_GETTER, ctx) } } val getterReturnTypeRef = getter.returnTypeRef @@ -54,8 +54,8 @@ object FirPropertyAccessorsTypesChecker : FirPropertyChecker() { } if (getterReturnType != property.returnTypeRef.coneType) { val getterReturnTypeSource = getterReturnTypeRef.source - withSuppressedDiagnostics(getterReturnTypeRef, context) { - reporter.reportOn(getterReturnTypeSource, FirErrors.WRONG_GETTER_RETURN_TYPE, propertyType, getterReturnType, context) + withSuppressedDiagnostics(getterReturnTypeRef, ctx) { + reporter.reportOn(getterReturnTypeSource, FirErrors.WRONG_GETTER_RETURN_TYPE, propertyType, getterReturnType, it) } } } @@ -65,26 +65,26 @@ object FirPropertyAccessorsTypesChecker : FirPropertyChecker() { val setter = property.setter ?: return val propertyType = property.returnTypeRef.coneType - withSuppressedDiagnostics(setter, context) { + withSuppressedDiagnostics(setter, context) { ctx -> if (property.isVal) { - reporter.reportOn(setter.source, FirErrors.VAL_WITH_SETTER, context) + reporter.reportOn(setter.source, FirErrors.VAL_WITH_SETTER, ctx) } - checkAccessorForDelegatedProperty(property, setter, context, reporter) + checkAccessorForDelegatedProperty(property, setter, ctx, reporter) val visibilityCompareResult = setter.visibility.compareTo(property.visibility) if (visibilityCompareResult == null || visibilityCompareResult > 0) { - reporter.reportOn(setter.source, FirErrors.SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY, context) + reporter.reportOn(setter.source, FirErrors.SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY, ctx) } if (property.symbol.callableId.classId != null && property.delegate == null) { - val isLegallyAbstract = isLegallyAbstract(property, context) + val isLegallyAbstract = isLegallyAbstract(property, ctx) if (setter.visibility == Visibilities.Private && property.visibility != Visibilities.Private) { if (isLegallyAbstract) { - reporter.reportOn(setter.source, FirErrors.PRIVATE_SETTER_FOR_ABSTRACT_PROPERTY, context) + reporter.reportOn(setter.source, FirErrors.PRIVATE_SETTER_FOR_ABSTRACT_PROPERTY, ctx) } else if (property.isOpen) { - reporter.reportOn(setter.source, FirErrors.PRIVATE_SETTER_FOR_OPEN_PROPERTY, context) + reporter.reportOn(setter.source, FirErrors.PRIVATE_SETTER_FOR_OPEN_PROPERTY, ctx) } } if (isLegallyAbstract && setter.body != null) { - reporter.reportOn(setter.source, FirErrors.ABSTRACT_PROPERTY_WITH_SETTER, context) + reporter.reportOn(setter.source, FirErrors.ABSTRACT_PROPERTY_WITH_SETTER, ctx) } } @@ -99,8 +99,8 @@ object FirPropertyAccessorsTypesChecker : FirPropertyChecker() { } if (valueSetterType != propertyType) { - withSuppressedDiagnostics(valueSetterParameter, context) { - reporter.reportOn(valueSetterTypeSource, FirErrors.WRONG_SETTER_PARAMETER_TYPE, propertyType, valueSetterType, context) + withSuppressedDiagnostics(valueSetterParameter, ctx) { + reporter.reportOn(valueSetterTypeSource, FirErrors.WRONG_SETTER_PARAMETER_TYPE, propertyType, valueSetterType, ctx) } } @@ -110,8 +110,8 @@ object FirPropertyAccessorsTypesChecker : FirPropertyChecker() { } if (!setterReturnType.isUnit) { - withSuppressedDiagnostics(setter.returnTypeRef, context) { - reporter.reportOn(setter.returnTypeRef.source, FirErrors.WRONG_SETTER_RETURN_TYPE, context) + withSuppressedDiagnostics(setter.returnTypeRef, ctx) { + reporter.reportOn(setter.returnTypeRef.source, FirErrors.WRONG_SETTER_RETURN_TYPE, ctx) } } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt index f8990cd9ff3..5c515a16d36 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt @@ -41,58 +41,58 @@ object FirSupertypesChecker : FirClassChecker() { var classAppeared = false val superClassSymbols = hashSetOf() for (superTypeRef in declaration.superTypeRefs) { - withSuppressedDiagnostics(superTypeRef, context) { + withSuppressedDiagnostics(superTypeRef, context) { ctx -> val coneType = superTypeRef.coneType if (!nullableSupertypeReported && coneType.nullability == ConeNullability.NULLABLE) { - reporter.reportOn(superTypeRef.source, FirErrors.NULLABLE_SUPERTYPE, context) + reporter.reportOn(superTypeRef.source, FirErrors.NULLABLE_SUPERTYPE, ctx) nullableSupertypeReported = true } if (!extensionFunctionSupertypeReported && coneType.isExtensionFunctionType && - !context.session.languageVersionSettings.supportsFeature(LanguageFeature.FunctionalTypeWithExtensionAsSupertype) + !ctx.session.languageVersionSettings.supportsFeature(LanguageFeature.FunctionalTypeWithExtensionAsSupertype) ) { - reporter.reportOn(superTypeRef.source, FirErrors.SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE, context) + reporter.reportOn(superTypeRef.source, FirErrors.SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE, ctx) extensionFunctionSupertypeReported = true } val lookupTag = coneType.safeAs()?.lookupTag ?: return@withSuppressedDiagnostics - val superTypeSymbol = lookupTag.toSymbol(context.session) + val superTypeSymbol = lookupTag.toSymbol(ctx.session) if (superTypeSymbol is FirRegularClassSymbol) { if (!superClassSymbols.add(superTypeSymbol)) { - reporter.reportOn(superTypeRef.source, FirErrors.SUPERTYPE_APPEARS_TWICE, context) + reporter.reportOn(superTypeRef.source, FirErrors.SUPERTYPE_APPEARS_TWICE, ctx) } if (superTypeSymbol.classKind != ClassKind.INTERFACE) { if (classAppeared) { - reporter.reportOn(superTypeRef.source, FirErrors.MANY_CLASSES_IN_SUPERTYPE_LIST, context) + reporter.reportOn(superTypeRef.source, FirErrors.MANY_CLASSES_IN_SUPERTYPE_LIST, ctx) } else { classAppeared = true } if (!interfaceWithSuperclassReported) { - reporter.reportOn(superTypeRef.source, FirErrors.INTERFACE_WITH_SUPERCLASS, context) + reporter.reportOn(superTypeRef.source, FirErrors.INTERFACE_WITH_SUPERCLASS, ctx) interfaceWithSuperclassReported = true } } val isObject = superTypeSymbol.classKind == ClassKind.OBJECT if (!finalSupertypeReported && !isObject && superTypeSymbol.modality == Modality.FINAL) { - reporter.reportOn(superTypeRef.source, FirErrors.FINAL_SUPERTYPE, context) + reporter.reportOn(superTypeRef.source, FirErrors.FINAL_SUPERTYPE, ctx) finalSupertypeReported = true } if (!singletonInSupertypeReported && isObject) { - reporter.reportOn(superTypeRef.source, FirErrors.SINGLETON_IN_SUPERTYPE, context) + reporter.reportOn(superTypeRef.source, FirErrors.SINGLETON_IN_SUPERTYPE, ctx) singletonInSupertypeReported = true } } - checkAnnotationOnSuperclass(superTypeRef, context, reporter) + checkAnnotationOnSuperclass(superTypeRef, ctx, reporter) - val fullyExpandedType = coneType.fullyExpandedType(context.session) - val symbol = fullyExpandedType.toSymbol(context.session) + val fullyExpandedType = coneType.fullyExpandedType(ctx.session) + val symbol = fullyExpandedType.toSymbol(ctx.session) - checkClassCannotBeExtendedDirectly(symbol, reporter, superTypeRef, context) + checkClassCannotBeExtendedDirectly(symbol, reporter, superTypeRef, ctx) if (coneType.typeArguments.isNotEmpty()) { - checkProjectionInImmediateArgumentToSupertype(coneType, superTypeRef, reporter, context) + checkProjectionInImmediateArgumentToSupertype(coneType, superTypeRef, reporter, ctx) } else { - checkExpandedTypeCannotBeInherited(symbol, fullyExpandedType, reporter, superTypeRef, coneType, context) + checkExpandedTypeCannotBeInherited(symbol, fullyExpandedType, reporter, superTypeRef, coneType, ctx) } } } @@ -112,7 +112,7 @@ object FirSupertypesChecker : FirClassChecker() { for (annotation in superTypeRef.annotations) { withSuppressedDiagnostics(annotation, context) { if (annotation.useSiteTarget != null) { - reporter.reportOn(annotation.source, FirErrors.ANNOTATION_ON_SUPERCLASS, context) + reporter.reportOn(annotation.source, FirErrors.ANNOTATION_ON_SUPERCLASS, it) } } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirTopLevelPropertiesChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirTopLevelPropertiesChecker.kt index 99cecaa0cb7..3a5c803c502 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirTopLevelPropertiesChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirTopLevelPropertiesChecker.kt @@ -38,16 +38,16 @@ object FirTopLevelPropertiesChecker : FirPropertyChecker() { // So, our source of truth should be the full modifier list retrieved from the source. val modifierList = source.getModifierList() - withSuppressedDiagnostics(declaration, context) { + withSuppressedDiagnostics(declaration, context) { ctx -> checkPropertyInitializer( containingClass = null, declaration, modifierList, isInitialized = declaration.initializer != null, reporter, - context + ctx ) - checkExpectDeclarationVisibilityAndBody(declaration, source, reporter, context) + checkExpectDeclarationVisibilityAndBody(declaration, source, reporter, ctx) } } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionAnnotationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionAnnotationChecker.kt index 1eb46108644..aa07ecd5302 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionAnnotationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionAnnotationChecker.kt @@ -41,12 +41,12 @@ object FirExpressionAnnotationChecker : FirBasicExpressionChecker() { val useSiteTarget = annotation.useSiteTarget ?: expression.getDefaultUseSiteTarget(annotation, context) val existingTargetsForAnnotation = annotationsMap.getOrPut(annotation.annotationTypeRef.coneType) { arrayListOf() } - withSuppressedDiagnostics(annotation, context) { - if (KotlinTarget.EXPRESSION !in annotation.getAllowedAnnotationTargets(context.session)) { - reporter.reportOn(annotation.source, FirErrors.WRONG_ANNOTATION_TARGET, "expression", context) + withSuppressedDiagnostics(annotation, context) { ctx -> + if (KotlinTarget.EXPRESSION !in annotation.getAllowedAnnotationTargets(ctx.session)) { + reporter.reportOn(annotation.source, FirErrors.WRONG_ANNOTATION_TARGET, "expression", ctx) } - checkRepeatedAnnotation(useSiteTarget, existingTargetsForAnnotation, annotation, context, reporter) + checkRepeatedAnnotation(useSiteTarget, existingTargetsForAnnotation, annotation, ctx, reporter) } existingTargetsForAnnotation.add(useSiteTarget) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirLoopConditionChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirLoopConditionChecker.kt index 4302e7d570a..114e82d32f8 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirLoopConditionChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirLoopConditionChecker.kt @@ -17,7 +17,7 @@ object FirLoopConditionChecker : FirLoopExpressionChecker() { if (expression is FirErrorLoop) return val condition = expression.condition withSuppressedDiagnostics(condition, context) { - checkCondition(condition, context, reporter) + checkCondition(condition, it, reporter) } } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirWhenConditionChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirWhenConditionChecker.kt index ade14b9f8c3..ae7a18645ee 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirWhenConditionChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirWhenConditionChecker.kt @@ -25,7 +25,7 @@ object FirWhenConditionChecker : FirWhenExpressionChecker() { val condition = branch.condition if (condition is FirElseIfTrueCondition) continue withSuppressedDiagnostics(condition, context) { - checkCondition(condition, context, reporter) + checkCondition(condition, it, reporter) } } if (expression.subject != null) { @@ -66,4 +66,4 @@ object FirWhenConditionChecker : FirWhenExpressionChecker() { } } } -} \ No newline at end of file +} diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirOptInUsageTypeRefChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirOptInUsageTypeRefChecker.kt index 15b3ba246ea..c98ffd35820 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirOptInUsageTypeRefChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirOptInUsageTypeRefChecker.kt @@ -40,7 +40,7 @@ object FirOptInUsageTypeRefChecker : FirTypeRefChecker() { if (annotation.getAnnotationClassForOptInMarker(context.session) != null) { if (annotation.useSiteTarget == AnnotationUseSiteTarget.RECEIVER) { withSuppressedDiagnostics(annotation, context) { - reporter.reportOn(annotation.source, FirErrors.OPT_IN_MARKER_ON_WRONG_TARGET, "parameter", context) + reporter.reportOn(annotation.source, FirErrors.OPT_IN_MARKER_ON_WRONG_TARGET, "parameter", it) } } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt index 801bb649bd6..3406d920a59 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt @@ -29,7 +29,7 @@ object FirTypeAnnotationChecker : FirTypeRefChecker() { if (KotlinTarget.TYPE !in annotationTargets) { val useSiteTarget = annotation.useSiteTarget if (useSiteTarget == null || KotlinTarget.USE_SITE_MAPPING[useSiteTarget] !in annotationTargets) { - reporter.reportOn(annotation.source, FirErrors.WRONG_ANNOTATION_TARGET, "type usage", context) + reporter.reportOn(annotation.source, FirErrors.WRONG_ANNOTATION_TARGET, "type usage", it) } } } diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/suppressOnDeclarationItself.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/suppressOnDeclarationItself.kt new file mode 100644 index 00000000000..2710f8690e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/suppressOnDeclarationItself.kt @@ -0,0 +1,7 @@ +// FIR_IDENTICAL + +class A { + @Suppress("NOTHING_TO_OVERRIDE") + override fun foo() {} +} + diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/suppressOnDeclarationItself.txt b/compiler/testData/diagnostics/tests/suppress/oneWarning/suppressOnDeclarationItself.txt new file mode 100644 index 00000000000..1b25316b7ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/suppressOnDeclarationItself.txt @@ -0,0 +1,9 @@ +package + +public final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + @kotlin.Suppress(names = {"NOTHING_TO_OVERRIDE"}) public open fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} 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 fbcc66f7f9e..3e645bd2f39 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 @@ -30402,6 +30402,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { public void testOnTypeParameter() throws Exception { runTest("compiler/testData/diagnostics/tests/suppress/oneWarning/onTypeParameter.kt"); } + + @Test + @TestMetadata("suppressOnDeclarationItself.kt") + public void testSuppressOnDeclarationItself() throws Exception { + runTest("compiler/testData/diagnostics/tests/suppress/oneWarning/suppressOnDeclarationItself.kt"); + } } } diff --git a/plugins/parcelize/parcelize-compiler/parcelize-fir/src/org/jetbrains/kotlin/parcelize/fir/diagnostics/FirParcelizeClassChecker.kt b/plugins/parcelize/parcelize-compiler/parcelize-fir/src/org/jetbrains/kotlin/parcelize/fir/diagnostics/FirParcelizeClassChecker.kt index 36249763fdb..4ba33e74f18 100644 --- a/plugins/parcelize/parcelize-compiler/parcelize-fir/src/org/jetbrains/kotlin/parcelize/fir/diagnostics/FirParcelizeClassChecker.kt +++ b/plugins/parcelize/parcelize-compiler/parcelize-fir/src/org/jetbrains/kotlin/parcelize/fir/diagnostics/FirParcelizeClassChecker.kt @@ -112,7 +112,7 @@ object FirParcelizeClassChecker : FirClassChecker() { } else { SourceElementPositioningStrategies.NAME_IDENTIFIER } - reporter.reportOn(klass.source, KtErrorsParcelize.DEPRECATED_PARCELER, context, positioningStrategy = strategy) + reporter.reportOn(klass.source, KtErrorsParcelize.DEPRECATED_PARCELER, it, positioningStrategy = strategy) } } }