Skip to content

Commit

Permalink
Properly revert old behaviour of Xlint
Browse files Browse the repository at this point in the history
  • Loading branch information
rochala committed May 7, 2024
1 parent 44d593d commit df8e8ba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions compiler/src/dotty/tools/dotc/config/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 11 additions & 0 deletions compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "") =
Expand Down

0 comments on commit df8e8ba

Please sign in to comment.