Skip to content

Commit 7a3aac7

Browse files
committed
Changes in parameter parsing & deprecation of -Xlint
1 parent 25fc269 commit 7a3aac7

File tree

9 files changed

+58
-46
lines changed

9 files changed

+58
-46
lines changed

compiler/src/dotty/tools/dotc/config/CliCommand.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ trait CliCommand:
8686
protected def isVerbose(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
8787
s.name.startsWith("-V") && s.name != "-V"
8888
protected def isWarning(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
89-
s.name.startsWith("-W") && s.name != "-W" || s.name == "-Xlint"
89+
s.name.startsWith("-W") && s.name != "-W"
9090
protected def isAdvanced(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
9191
s.name.startsWith("-X") && s.name != "-X"
9292
protected def isPrivate(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ private sealed trait WarningSettings:
295295
|to prevent the shell from expanding patterns.""".stripMargin,
296296
)
297297

298-
val Xlint: Setting[List[ChoiceWithHelp[String]]] = UncompleteMultiChoiceHelpSetting(
299-
AdvancedSetting,
300-
name = "Xlint",
298+
val Wshadow: Setting[List[ChoiceWithHelp[String]]] = MultiChoiceHelpSetting(
299+
WarningSetting,
300+
name = "Wshadow",
301301
helpArg = "advanced warning",
302302
descr = "Enable or disable specific `lint` warnings",
303303
choices = List(
@@ -308,9 +308,9 @@ private sealed trait WarningSettings:
308308
default = Nil
309309
)
310310

311-
object XlintHas:
311+
object WshadowHas:
312312
def allOr(s: String)(using Context) =
313-
Xlint.value.pipe(us => us.contains("all") || us.contains(s))
313+
Wshadow.value.pipe(us => us.contains("all") || us.contains(s))
314314
def privateShadow(using Context) =
315315
allOr("private-shadow")
316316
def typeParameterShadow(using Context) =
@@ -356,6 +356,10 @@ private sealed trait XSettings:
356356
}
357357

358358
val XmacroSettings: Setting[List[String]] = MultiStringSetting(AdvancedSetting, "Xmacro-settings", "setting1,setting2,..settingN", "List of settings which exposed to the macros")
359+
360+
// Deprecated
361+
val Xlint: Setting[_] = DeprecatedSetting(AdvancedSetting, "Xlint", "Enable or disable specific warnings", "Use -Wshadow to enable shadowing lints or -W:<opt> to enable specific sets of warnings.")
362+
359363
end XSettings
360364

361365
/** -Y "Forking" as in forked tongue or "Private" settings */

compiler/src/dotty/tools/dotc/config/Settings.scala

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,15 @@ object Settings:
7070
aliases: List[String] = Nil,
7171
depends: List[(Setting[?], Any)] = Nil,
7272
ignoreInvalidArgs: Boolean = false,
73-
propertyClass: Option[Class[?]] = None)(private[Settings] val idx: Int) {
73+
propertyClass: Option[Class[?]] = None,
74+
deprecationMsg: Option[String] = None)(private[Settings] val idx: Int) {
7475

7576
assert(name.startsWith(s"-$category"), s"Setting $name does not start with category -$category")
7677

78+
// Without the following assertion, it would be easy to mistakenly try to pass a file to a setting that ignores invalid args.
79+
// Example: -opt Main.scala would be interpreted as -opt:Main.scala, and the source file would be ignored.
80+
assert(!(summon[ClassTag[T]] == ListTag && ignoreInvalidArgs), s"Ignoring invalid args is not supported for multivalue settings: $name")
81+
7782
val allFullNames: List[String] = s"$name" :: s"-$name" :: aliases
7883

7984
def valueIn(state: SettingsState): T = state.value(idx).asInstanceOf[T]
@@ -150,45 +155,45 @@ object Settings:
150155
update(x, args)
151156
catch case _: NumberFormatException =>
152157
fail(s"$argValue is not an integer argument for $name", args)
158+
159+
def setOutput(argValue: String, args: List[String]) =
160+
val path = Directory(argValue)
161+
val isJar = path.extension == "jar"
162+
if (!isJar && !path.isDirectory)
163+
fail(s"'$argValue' does not exist or is not a directory or .jar file", args)
164+
else {
165+
val output = if (isJar) JarArchive.create(path) else new PlainDirectory(path)
166+
update(output, args)
167+
}
168+
169+
def appendList(strings: List[String], args: List[String]) =
170+
choices match
171+
case Some(valid) => strings.filterNot(valid.contains) match
172+
case Nil => update(strings, args)
173+
case invalid => invalidChoices(invalid)
174+
case _ => update(strings, args)
175+
153176

154177
def doSet(argRest: String) =
155178
((summon[ClassTag[T]], args): @unchecked) match {
156179
case (BooleanTag, _) =>
157180
setBoolean(argRest, args)
158181
case (OptionTag, _) =>
159182
update(Some(propertyClass.get.getConstructor().newInstance()), args)
160-
case (ListTag, _) =>
161-
if (argRest.isEmpty) missingArg
162-
else
163-
val strings = argRest.split(",").toList
164-
choices match
165-
case Some(valid) => strings.filterNot(valid.contains) match
166-
case Nil => update(strings, args)
167-
case invalid => invalidChoices(invalid)
168-
case _ => update(strings, args)
183+
case (ListTag, args) if argRest.nonEmpty =>
184+
val strings = argRest.split(",").toList
185+
appendList(strings, args)
186+
case (ListTag, arg2 :: args2) if !(arg2 startsWith "-")=>
187+
appendList(arg2 :: Nil, args2)
169188
case (StringTag, _) if argRest.nonEmpty || choices.exists(_.contains("")) =>
170189
setString(argRest, args)
171190
case (StringTag, arg2 :: args2) =>
172191
if (arg2 startsWith "-") missingArg
173192
else setString(arg2, args2)
174-
case (OutputTag, _) if argRest.nonEmpty =>
175-
val path = Directory(argRest)
176-
val isJar = path.extension == "jar"
177-
if (!isJar && !path.isDirectory)
178-
fail(s"'$argRest' does not exist or is not a directory or .jar file", args)
179-
else {
180-
val output = if (isJar) JarArchive.create(path) else new PlainDirectory(path)
181-
update(output, args)
182-
}
183-
case (OutputTag, arg :: args) =>
184-
val path = Directory(arg)
185-
val isJar = path.extension == "jar"
186-
if (!isJar && !path.isDirectory)
187-
fail(s"'$arg' does not exist or is not a directory or .jar file", args)
188-
else {
189-
val output = if (isJar) JarArchive.create(path) else new PlainDirectory(path)
190-
update(output, args)
191-
}
193+
case (OutputTag, args) if argRest.nonEmpty =>
194+
setOutput(argRest, args)
195+
case (OutputTag, arg2 :: args2) =>
196+
setOutput(arg2, args2)
192197
case (IntTag, args) if argRest.nonEmpty =>
193198
setInt(argRest, args)
194199
case (IntTag, arg2 :: args2) =>
@@ -214,7 +219,10 @@ object Settings:
214219
if(prefix.isEmpty) arg.dropWhile(_ != ':').drop(1) else arg.drop(prefix.get.length)
215220

216221
if matches(arg) then
217-
doSet(argValRest)
222+
if deprecationMsg.isDefined then
223+
warn(s"Option $name is deprecated: ${deprecationMsg.get}", args)
224+
else
225+
doSet(argValRest)
218226
else
219227
state
220228
}
@@ -334,9 +342,6 @@ object Settings:
334342
def MultiChoiceHelpSetting(category: String, name: String, helpArg: String, descr: String, choices: List[ChoiceWithHelp[String]], default: List[ChoiceWithHelp[String]], aliases: List[String] = Nil): Setting[List[ChoiceWithHelp[String]]] =
335343
publish(Setting(category, validateAndPrependName(name), descr, default, helpArg, Some(choices), aliases = aliases.map(validateSetting)))
336344

337-
def UncompleteMultiChoiceHelpSetting(category: String, name: String, helpArg: String, descr: String, choices: List[ChoiceWithHelp[String]], default: List[ChoiceWithHelp[String]], aliases: List[String] = Nil): Setting[List[ChoiceWithHelp[String]]] =
338-
publish(Setting(category, validateAndPrependName(name), descr, default, helpArg, Some(choices), aliases = aliases.map(validateSetting), ignoreInvalidArgs = true))
339-
340345
def IntSetting(category: String, name: String, descr: String, default: Int, aliases: List[String] = Nil): Setting[Int] =
341346
publish(Setting(category, validateAndPrependName(name), descr, default, aliases = aliases.map(validateSetting)))
342347

@@ -364,5 +369,8 @@ object Settings:
364369

365370
def OptionSetting[T: ClassTag](category: String, name: String, descr: String, aliases: List[String] = Nil): Setting[Option[T]] =
366371
publish(Setting(category, validateAndPrependName(name), descr, None, propertyClass = Some(summon[ClassTag[T]].runtimeClass), aliases = aliases.map(validateSetting)))
372+
373+
def DeprecatedSetting(category: String, name: String, descr: String, deprecationMsg: String): Setting[Boolean] =
374+
publish(Setting(category, validateAndPrependName(name), descr, false, deprecationMsg = Some(deprecationMsg)))
367375
}
368376
end Settings

compiler/src/dotty/tools/dotc/transform/CheckShadowing.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CheckShadowing extends MiniPhase:
5151

5252
override def isRunnable(using Context): Boolean =
5353
super.isRunnable &&
54-
ctx.settings.Xlint.value.nonEmpty &&
54+
ctx.settings.Wshadow.value.nonEmpty &&
5555
!ctx.isJava
5656

5757
// Setup before the traversal
@@ -266,12 +266,12 @@ object CheckShadowing:
266266
/** Get the shadowing analysis's result */
267267
def getShadowingResult(using Context): ShadowResult =
268268
val privateWarnings: List[ShadowWarning] =
269-
if ctx.settings.XlintHas.privateShadow then
269+
if ctx.settings.WshadowHas.privateShadow then
270270
privateShadowWarnings.toList
271271
else
272272
Nil
273273
val typeParamWarnings: List[ShadowWarning] =
274-
if ctx.settings.XlintHas.typeParameterShadow then
274+
if ctx.settings.WshadowHas.typeParameterShadow then
275275
typeParamShadowWarnings.toList
276276
else
277277
Nil

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CompilationTests {
3131
@Test def pos: Unit = {
3232
implicit val testGroup: TestGroup = TestGroup("compilePos")
3333
var tests = List(
34-
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init", "-Wunused:all", "-Xlint:private-shadow", "-Xlint:type-parameter-shadow"), FileFilter.include(TestSources.posLintingAllowlist)),
34+
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init", "-Wunused:all", "-Wshadow:private-shadow", "-Wshadow:type-parameter-shadow"), FileFilter.include(TestSources.posLintingAllowlist)),
3535
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init"), FileFilter.exclude(TestSources.posLintingAllowlist)),
3636
compileFilesInDir("tests/pos-deep-subtype", allowDeepSubtypes),
3737
compileFilesInDir("tests/pos-special/sourcepath/outer", defaultOptions.and("-sourcepath", "tests/pos-special/sourcepath")),

tests/neg/i17612b/i17612b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -Xfatal-warnings -Xlint:private-shadow -source:3.3
1+
//> using options -Xfatal-warnings -Wshadow:private-shadow -source:3.3
22

33
object i17612b:
44

tests/neg/i17613b/i17613b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -Xlint:type-parameter-shadow -Xfatal-warnings
1+
//> using options -Wshadow:type-parameter-shadow -Xfatal-warnings
22

33
object i17613b:
44
import importTry._

tests/warn/i17612a.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -Xlint:private-shadow -source:3.3
1+
//> using options -Wshadow:private-shadow -source:3.3
22

33
object i17612a:
44
class Base(var x: Int, val y: Int, var z: Int):

tests/warn/i17613a.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -Xlint:type-parameter-shadow
1+
//> using options -Wshadow:type-parameter-shadow
22

33
object i17613a:
44
class B:

0 commit comments

Comments
 (0)