From 65b64c71965836b0e5610b465e52833b95fce801 Mon Sep 17 00:00:00 2001 From: rochala Date: Tue, 7 May 2024 09:11:57 +0200 Subject: [PATCH] Properly revert old behaviour of Xlint --- community-build/community-projects/verify | 2 +- .../src/dotty/tools/dotc/config/ScalaSettings.scala | 2 +- compiler/src/dotty/tools/dotc/config/Settings.scala | 10 +++++++--- .../dotty/tools/dotc/config/ScalaSettingsTests.scala | 11 +++++++++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/community-build/community-projects/verify b/community-build/community-projects/verify index 81c1ec3e0d75..f82bb3f52623 160000 --- a/community-build/community-projects/verify +++ b/community-build/community-projects/verify @@ -1 +1 @@ -Subproject commit 81c1ec3e0d754b221dadb97d81d126338a897271 +Subproject commit f82bb3f52623e44f02b4b43f8bdf27f4f0a7d3d4 diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 5dc7ba821fa6..86b657ddf00d 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -360,7 +360,7 @@ private sealed trait XSettings: val XmacroSettings: Setting[List[String]] = MultiStringSetting(AdvancedSetting, "Xmacro-settings", "setting1,setting2,..settingN", "List of settings which exposed to the macros") @deprecated(message = "Superseded by -Wshadow, Scheduled for removal", since = "3.5.0") - val Xlint: Setting[_] = BooleanSetting(AdvancedSetting, "Xlint", "Enable or disable specific warnings", deprecation = Some(Deprecation("Use -Wshadow to enable shadowing lints. Scheduled for removal."))) + val Xlint: Setting[_] = BooleanSetting(AdvancedSetting, "Xlint", "Enable or disable specific warnings", deprecation = Some(Deprecation("Use -Wshadow to enable shadowing lints. Scheduled for removal.")), ignoreInvalidArgs = true) end XSettings diff --git a/compiler/src/dotty/tools/dotc/config/Settings.scala b/compiler/src/dotty/tools/dotc/config/Settings.scala index 786268f841a8..1e2ced4d65a7 100644 --- a/compiler/src/dotty/tools/dotc/config/Settings.scala +++ b/compiler/src/dotty/tools/dotc/config/Settings.scala @@ -251,7 +251,11 @@ object Settings: def argValRest: String = if(prefix.isEmpty) arg.dropWhile(_ != ':').drop(1) else arg.drop(prefix.get.length) - if matches(arg) then doSet(argValRest) + if matches(arg) then + deprecation match + case Some(Deprecation(msg, _)) if ignoreInvalidArgs => // a special case for Xlint + state.deprecated(s"Option $name is deprecated: $msg") + case _ => doSet(argValRest) else state end tryToSet @@ -367,8 +371,8 @@ object Settings: assert(!name.startsWith("-"), s"Setting $name cannot start with -") "-" + name - def BooleanSetting(category: SettingCategory, name: String, descr: String, initialValue: Boolean = false, aliases: List[String] = Nil, preferPrevious: Boolean = false, deprecation: Option[Deprecation] = None): Setting[Boolean] = - publish(Setting(category, prependName(name), descr, initialValue, aliases = aliases, preferPrevious = preferPrevious, deprecation = deprecation)) + def BooleanSetting(category: SettingCategory, name: String, descr: String, initialValue: Boolean = false, aliases: List[String] = Nil, preferPrevious: Boolean = false, deprecation: Option[Deprecation] = None, ignoreInvalidArgs: Boolean = false): Setting[Boolean] = + publish(Setting(category, prependName(name), descr, initialValue, aliases = aliases, preferPrevious = preferPrevious, deprecation = deprecation, ignoreInvalidArgs = ignoreInvalidArgs)) def StringSetting(category: SettingCategory, name: String, helpArg: String, descr: String, default: String, aliases: List[String] = Nil, deprecation: Option[Deprecation] = None): Setting[String] = publish(Setting(category, prependName(name), descr, default, helpArg, aliases = aliases, deprecation = deprecation)) diff --git a/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala b/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala index 28dd5e307bc5..3dc4f4e4ec5e 100644 --- a/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala +++ b/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala @@ -148,6 +148,17 @@ class ScalaSettingsTests: val conf = settings.processArguments(argSummary, processAll = true, skipped = Nil) assert(newSetting.isDefaultIn(conf.sstate), s"Setting $deprecatedArgument was forwarded to ${newSetting.name}, when it should be ignored because first option was erroreus") + // -Xlint was handled in a special way when it was added, making in hard to deprecate it. + // For now on we will retain old behavior, in next version we will emit deprecation warning. + // It is also scheduled for removal in future versions. + @Test def `Make Xlint to ignore invalid args`: Unit = + val settings = ScalaSettings + val args = List("-Xlint:-unused,_") + val argSummary = ArgsSummary(settings.defaultState, args, errors = Nil, warnings = Nil) + val conf = settings.processArguments(argSummary, processAll = true, skipped = Nil) + assert(conf.warnings.contains("Option -Xlint is deprecated: Use -Wshadow to enable shadowing lints. Scheduled for removal.")) + assert(conf.errors.isEmpty) + @nowarn("cat=deprecation") @Test def `Deprecated options aliases are correctly mapped to their replacements`: Unit = def createTestCase(oldSetting: Setting[_], newSetting: Setting[_], value: String = "") =