[FIR] Implement flag for disabling warning on error suppression
#KT-61129
This commit is contained in:
committed by
Space Team
parent
c32a0a83f9
commit
969c716c76
+1
@@ -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
|
||||
|
||||
+11
@@ -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<AnalysisFlag<*>, Any> {
|
||||
return HashMap<AnalysisFlag<*>, 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,4 +59,7 @@ object AnalysisFlags {
|
||||
|
||||
@JvmStatic
|
||||
val eagerResolveOfLightClasses by AnalysisFlag.Delegates.Boolean
|
||||
|
||||
@JvmStatic
|
||||
val dontWarnOnErrorSuppression by AnalysisFlag.Delegates.Boolean
|
||||
}
|
||||
|
||||
+2
@@ -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) {
|
||||
|
||||
+1
@@ -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)),
|
||||
|
||||
+1
@@ -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 ---------------------
|
||||
|
||||
+2
@@ -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=<path> Dump detailed performance statistics to the specified file
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
@Suppress("UNSUPPORTED")
|
||||
fun foo() {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
$TESTDATA_DIR$/errorSuppression.kt
|
||||
-language-version
|
||||
2.0
|
||||
-Xdont-warn-on-error-suppression
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
@@ -0,0 +1,2 @@
|
||||
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
|
||||
OK
|
||||
@@ -0,0 +1,5 @@
|
||||
$TESTDATA_DIR$/errorSuppression.kt
|
||||
-language-version
|
||||
2.0
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
@@ -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
|
||||
+2
@@ -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=<path> Dump detailed performance statistics to the specified file
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user