From 969c716c7686003150f83b1597415a618538b2fa Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Mon, 14 Aug 2023 11:58:26 +0200 Subject: [PATCH] [FIR] Implement flag for disabling warning on error suppression #KT-61129 --- .../arguments/CommonCompilerArgumentsCopyGenerated.kt | 1 + .../cli/common/arguments/CommonCompilerArguments.kt | 11 +++++++++++ .../src/org/jetbrains/kotlin/config/AnalysisFlags.kt | 3 +++ .../expression/FirAnnotationExpressionChecker.kt | 2 ++ .../test/builders/LanguageVersionSettingsBuilder.kt | 1 + .../test/directives/LanguageSettingsDirectives.kt | 1 + compiler/testData/cli/js/jsExtraHelp.out | 2 ++ compiler/testData/cli/jvm/errorSuppression.kt | 3 +++ .../testData/cli/jvm/errorSuppressionNoWarning.args | 6 ++++++ .../testData/cli/jvm/errorSuppressionNoWarning.out | 2 ++ .../testData/cli/jvm/errorSuppressionWarning.args | 5 +++++ compiler/testData/cli/jvm/errorSuppressionWarning.out | 5 +++++ compiler/testData/cli/jvm/extraHelp.out | 2 ++ .../org/jetbrains/kotlin/cli/CliTestGenerated.java | 10 ++++++++++ 14 files changed, 54 insertions(+) create mode 100644 compiler/testData/cli/jvm/errorSuppression.kt create mode 100644 compiler/testData/cli/jvm/errorSuppressionNoWarning.args create mode 100644 compiler/testData/cli/jvm/errorSuppressionNoWarning.out create mode 100644 compiler/testData/cli/jvm/errorSuppressionWarning.args create mode 100644 compiler/testData/cli/jvm/errorSuppressionWarning.out diff --git a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt index 52630245a9c..04611e68ecc 100644 --- a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt +++ b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt @@ -24,6 +24,7 @@ fun copyCommonCompilerArguments(from: CommonCompilerArguments, to: CommonCompile to.disableDefaultScriptingPlugin = from.disableDefaultScriptingPlugin to.disablePhases = from.disablePhases?.copyOf() to.disableUltraLightClasses = from.disableUltraLightClasses + to.dontWarnOnErrorSuppression = from.dontWarnOnErrorSuppression to.dumpDirectory = from.dumpDirectory to.dumpOnlyFqName = from.dumpOnlyFqName to.dumpPerf = from.dumpPerf diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index 41195d595ac..fe6661a4458 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -763,6 +763,16 @@ abstract class CommonCompilerArguments : CommonToolArguments() { field = value } + @Argument( + value = "-Xdont-warn-on-error-suppression", + description = "Don't report a warning when an error is suppressed. Only affects K2." + ) + var dontWarnOnErrorSuppression = false + set(value) { + checkFrozen() + field = value + } + @OptIn(IDEAPluginsCompatibilityAPI::class) open fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap, Any> { return HashMap, Any>().apply { @@ -787,6 +797,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() { put(AnalysisFlags.allowKotlinPackage, allowKotlinPackage) put(AnalysisFlags.builtInsFromSources, builtInsFromSources) put(AnalysisFlags.allowFullyQualifiedNameInKClass, true) + put(AnalysisFlags.dontWarnOnErrorSuppression, dontWarnOnErrorSuppression) } } diff --git a/compiler/config/src/org/jetbrains/kotlin/config/AnalysisFlags.kt b/compiler/config/src/org/jetbrains/kotlin/config/AnalysisFlags.kt index 865fa870af6..3d234572819 100644 --- a/compiler/config/src/org/jetbrains/kotlin/config/AnalysisFlags.kt +++ b/compiler/config/src/org/jetbrains/kotlin/config/AnalysisFlags.kt @@ -59,4 +59,7 @@ object AnalysisFlags { @JvmStatic val eagerResolveOfLightClasses by AnalysisFlag.Delegates.Boolean + + @JvmStatic + val dontWarnOnErrorSuppression by AnalysisFlag.Delegates.Boolean } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirAnnotationExpressionChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirAnnotationExpressionChecker.kt index fb7a1e26017..0173020a1eb 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirAnnotationExpressionChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirAnnotationExpressionChecker.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.expression import org.jetbrains.kotlin.KtSourceElement +import org.jetbrains.kotlin.config.AnalysisFlags import org.jetbrains.kotlin.config.ApiVersion import org.jetbrains.kotlin.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory0 @@ -234,6 +235,7 @@ object FirAnnotationExpressionChecker : FirAnnotationCallChecker() { reporter: DiagnosticReporter, context: CheckerContext, ) { + if (context.languageVersionSettings.getFlag(AnalysisFlags.dontWarnOnErrorSuppression)) return if (annotationClassId != StandardClassIds.Annotations.Suppress) return val nameExpressions = argumentMapping[StandardClassIds.Annotations.ParameterNames.suppressNames]?.unwrapVarargValue() ?: return for (nameExpression in nameExpressions) { diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt index 21914fff42b..984772cf7bf 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt @@ -103,6 +103,7 @@ class LanguageVersionSettingsBuilder { analysisFlag(AnalysisFlags.allowResultReturnType, trueOrNull(LanguageSettingsDirectives.ALLOW_RESULT_RETURN_TYPE in directives)), analysisFlag(AnalysisFlags.explicitApiMode, directives.singleOrZeroValue(LanguageSettingsDirectives.EXPLICIT_API_MODE)), analysisFlag(AnalysisFlags.allowKotlinPackage, trueOrNull(LanguageSettingsDirectives.ALLOW_KOTLIN_PACKAGE in directives)), + analysisFlag(AnalysisFlags.dontWarnOnErrorSuppression, trueOrNull(LanguageSettingsDirectives.DONT_WARN_ON_ERROR_SUPPRESSION in directives)), analysisFlag(JvmAnalysisFlags.jvmDefaultMode, directives.singleOrZeroValue(LanguageSettingsDirectives.JVM_DEFAULT_MODE)), analysisFlag(JvmAnalysisFlags.inheritMultifileParts, trueOrNull(LanguageSettingsDirectives.INHERIT_MULTIFILE_PARTS in directives)), diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/LanguageSettingsDirectives.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/LanguageSettingsDirectives.kt index ec7e6aa9751..50e47d6c236 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/LanguageSettingsDirectives.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/LanguageSettingsDirectives.kt @@ -99,6 +99,7 @@ object LanguageSettingsDirectives : SimpleDirectivesContainer() { val GENERATE_PROPERTY_ANNOTATIONS_METHODS by directive( description = "Enables corresponding analysis flag (JvmAnalysisFlags.generatePropertyAnnotationsMethods)" ) + val DONT_WARN_ON_ERROR_SUPPRESSION by directive("Don't emit warning when an error is suppressed") // --------------------- Utils --------------------- diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index 160190709d7..8e3600a096e 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -77,6 +77,8 @@ where advanced options include: Do not enable scripting plugin by default -Xdisable-phases Disable backend phases -Xdisable-ultra-light-classes Do not use the ultra light classes implementation + -Xdont-warn-on-error-suppression + Don't report a warning when an error is suppressed. Only affects K2. -Xdump-directory Dump backend state into directory -Xdump-fqname FqName of declaration that should be dumped -Xdump-perf= Dump detailed performance statistics to the specified file diff --git a/compiler/testData/cli/jvm/errorSuppression.kt b/compiler/testData/cli/jvm/errorSuppression.kt new file mode 100644 index 00000000000..d6ef9498a9c --- /dev/null +++ b/compiler/testData/cli/jvm/errorSuppression.kt @@ -0,0 +1,3 @@ +@Suppress("UNSUPPORTED") +fun foo() { +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/errorSuppressionNoWarning.args b/compiler/testData/cli/jvm/errorSuppressionNoWarning.args new file mode 100644 index 00000000000..deddf8f430f --- /dev/null +++ b/compiler/testData/cli/jvm/errorSuppressionNoWarning.args @@ -0,0 +1,6 @@ +$TESTDATA_DIR$/errorSuppression.kt +-language-version +2.0 +-Xdont-warn-on-error-suppression +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/errorSuppressionNoWarning.out b/compiler/testData/cli/jvm/errorSuppressionNoWarning.out new file mode 100644 index 00000000000..86ca0241885 --- /dev/null +++ b/compiler/testData/cli/jvm/errorSuppressionNoWarning.out @@ -0,0 +1,2 @@ +warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features +OK diff --git a/compiler/testData/cli/jvm/errorSuppressionWarning.args b/compiler/testData/cli/jvm/errorSuppressionWarning.args new file mode 100644 index 00000000000..b9e00619b06 --- /dev/null +++ b/compiler/testData/cli/jvm/errorSuppressionWarning.args @@ -0,0 +1,5 @@ +$TESTDATA_DIR$/errorSuppression.kt +-language-version +2.0 +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/errorSuppressionWarning.out b/compiler/testData/cli/jvm/errorSuppressionWarning.out new file mode 100644 index 00000000000..fe8f8ea92e6 --- /dev/null +++ b/compiler/testData/cli/jvm/errorSuppressionWarning.out @@ -0,0 +1,5 @@ +warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features +compiler/testData/cli/jvm/errorSuppression.kt:1:11: warning: this code uses error suppression for 'UNSUPPORTED'. While it might compile and work, the compiler behavior is UNSPECIFIED and WON'T BE PRESERVED. Please report your use case to the Kotlin issue tracker instead: https://kotl.in/issue +@Suppress("UNSUPPORTED") + ^ +OK diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 605d4de7b39..9d224733eb9 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -168,6 +168,8 @@ where advanced options include: Do not enable scripting plugin by default -Xdisable-phases Disable backend phases -Xdisable-ultra-light-classes Do not use the ultra light classes implementation + -Xdont-warn-on-error-suppression + Don't report a warning when an error is suppressed. Only affects K2. -Xdump-directory Dump backend state into directory -Xdump-fqname FqName of declaration that should be dumped -Xdump-perf= Dump detailed performance statistics to the specified file diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index de2172a7ac5..023263332e4 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -405,6 +405,16 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/enumEntriesNotEnabled.args"); } + @TestMetadata("errorSuppressionNoWarning.args") + public void testErrorSuppressionNoWarning() throws Exception { + runTest("compiler/testData/cli/jvm/errorSuppressionNoWarning.args"); + } + + @TestMetadata("errorSuppressionWarning.args") + public void testErrorSuppressionWarning() throws Exception { + runTest("compiler/testData/cli/jvm/errorSuppressionWarning.args"); + } + @TestMetadata("experimentalDeprecated.args") public void testExperimentalDeprecated() throws Exception { runTest("compiler/testData/cli/jvm/experimentalDeprecated.args");