Skip to content

Commit 65b64c7

Browse files
committed
Properly revert old behaviour of Xlint
1 parent 5e37806 commit 65b64c7

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

Diff for: community-build/community-projects/verify

Submodule verify updated 1 file

Diff for: compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ private sealed trait XSettings:
360360
val XmacroSettings: Setting[List[String]] = MultiStringSetting(AdvancedSetting, "Xmacro-settings", "setting1,setting2,..settingN", "List of settings which exposed to the macros")
361361

362362
@deprecated(message = "Superseded by -Wshadow, Scheduled for removal", since = "3.5.0")
363-
val Xlint: Setting[_] = BooleanSetting(AdvancedSetting, "Xlint", "Enable or disable specific warnings", deprecation = Some(Deprecation("Use -Wshadow to enable shadowing lints. Scheduled for removal.")))
363+
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)
364364

365365
end XSettings
366366

Diff for: compiler/src/dotty/tools/dotc/config/Settings.scala

+7-3
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ object Settings:
251251
def argValRest: String =
252252
if(prefix.isEmpty) arg.dropWhile(_ != ':').drop(1) else arg.drop(prefix.get.length)
253253

254-
if matches(arg) then doSet(argValRest)
254+
if matches(arg) then
255+
deprecation match
256+
case Some(Deprecation(msg, _)) if ignoreInvalidArgs => // a special case for Xlint
257+
state.deprecated(s"Option $name is deprecated: $msg")
258+
case _ => doSet(argValRest)
255259
else state
256260

257261
end tryToSet
@@ -367,8 +371,8 @@ object Settings:
367371
assert(!name.startsWith("-"), s"Setting $name cannot start with -")
368372
"-" + name
369373

370-
def BooleanSetting(category: SettingCategory, name: String, descr: String, initialValue: Boolean = false, aliases: List[String] = Nil, preferPrevious: Boolean = false, deprecation: Option[Deprecation] = None): Setting[Boolean] =
371-
publish(Setting(category, prependName(name), descr, initialValue, aliases = aliases, preferPrevious = preferPrevious, deprecation = deprecation))
374+
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] =
375+
publish(Setting(category, prependName(name), descr, initialValue, aliases = aliases, preferPrevious = preferPrevious, deprecation = deprecation, ignoreInvalidArgs = ignoreInvalidArgs))
372376

373377
def StringSetting(category: SettingCategory, name: String, helpArg: String, descr: String, default: String, aliases: List[String] = Nil, deprecation: Option[Deprecation] = None): Setting[String] =
374378
publish(Setting(category, prependName(name), descr, default, helpArg, aliases = aliases, deprecation = deprecation))

Diff for: compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala

+11
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ class ScalaSettingsTests:
148148
val conf = settings.processArguments(argSummary, processAll = true, skipped = Nil)
149149
assert(newSetting.isDefaultIn(conf.sstate), s"Setting $deprecatedArgument was forwarded to ${newSetting.name}, when it should be ignored because first option was erroreus")
150150

151+
// -Xlint was handled in a special way when it was added, making in hard to deprecate it.
152+
// For now on we will retain old behavior, in next version we will emit deprecation warning.
153+
// It is also scheduled for removal in future versions.
154+
@Test def `Make Xlint to ignore invalid args`: Unit =
155+
val settings = ScalaSettings
156+
val args = List("-Xlint:-unused,_")
157+
val argSummary = ArgsSummary(settings.defaultState, args, errors = Nil, warnings = Nil)
158+
val conf = settings.processArguments(argSummary, processAll = true, skipped = Nil)
159+
assert(conf.warnings.contains("Option -Xlint is deprecated: Use -Wshadow to enable shadowing lints. Scheduled for removal."))
160+
assert(conf.errors.isEmpty)
161+
151162
@nowarn("cat=deprecation")
152163
@Test def `Deprecated options aliases are correctly mapped to their replacements`: Unit =
153164
def createTestCase(oldSetting: Setting[_], newSetting: Setting[_], value: String = "") =

0 commit comments

Comments
 (0)