Skip to content

Commit 07f6581

Browse files
committedJun 20, 2023
Warn instead of fail for invalid -Xlint args
1 parent 175d4f3 commit 07f6581

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed
 

‎compiler/src/dotty/tools/dotc/Compiler.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Compiler {
3535
protected def frontendPhases: List[List[Phase]] =
3636
List(new Parser) :: // Compiler frontend: scanner, parser
3737
List(new TyperPhase) :: // Compiler frontend: namer, typer
38-
List(new CheckShadowing, new CheckUnused.PostTyper) :: // Check for unused elements // Check for shadowing elements
38+
List(new CheckUnused.PostTyper, new CheckShadowing) :: // Check for unused elements and shadowing elements
3939
List(new YCheckPositions) :: // YCheck positions
4040
List(new sbt.ExtractDependencies) :: // Sends information on classes' dependencies to sbt via callbacks
4141
List(new semanticdb.ExtractSemanticDB) :: // Extract info into .semanticdb files

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ private sealed trait XSettings:
307307

308308
val XmacroSettings: Setting[List[String]] = MultiStringSetting("-Xmacro-settings", "setting1,setting2,..settingN", "List of settings which exposed to the macros")
309309

310-
val Xlint: Setting[List[ChoiceWithHelp[String]]] = MultiChoiceHelpSetting(
310+
val Xlint: Setting[List[ChoiceWithHelp[String]]] = UncompleteMultiChoiceHelpSetting(
311311
name = "-Xlint",
312312
helpArg = "advanced warning",
313313
descr = "Enable or disable specific `lint` warnings",

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

+14-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ object Settings:
6262
prefix: String = "",
6363
aliases: List[String] = Nil,
6464
depends: List[(Setting[?], Any)] = Nil,
65+
ignoreInvalidArgs: Boolean = false,
6566
propertyClass: Option[Class[?]] = None)(private[Settings] val idx: Int) {
6667

6768
private var changed: Boolean = false
@@ -104,8 +105,16 @@ object Settings:
104105
def fail(msg: String, args: List[String]) =
105106
ArgsSummary(sstate, args, errors :+ msg, warnings)
106107

108+
def warn(msg: String, args: List[String]) =
109+
ArgsSummary(sstate, args, errors, warnings :+ msg)
110+
107111
def missingArg =
108-
fail(s"missing argument for option $name", args)
112+
val msg = s"missing argument for option $name"
113+
if ignoreInvalidArgs then warn(msg + ", the tag was ignored", args) else fail(msg, args)
114+
115+
def invalidChoices(invalid: List[String]) =
116+
val msg = s"invalid choice(s) for $name: ${invalid.mkString(",")}"
117+
if ignoreInvalidArgs then warn(msg + ", the tag was ignored", args) else fail(msg, args)
109118

110119
def setBoolean(argValue: String, args: List[String]) =
111120
if argValue.equalsIgnoreCase("true") || argValue.isEmpty then update(true, args)
@@ -144,7 +153,7 @@ object Settings:
144153
choices match
145154
case Some(valid) => strings.filterNot(valid.contains) match
146155
case Nil => update(strings, args)
147-
case invalid => fail(s"invalid choice(s) for $name: ${invalid.mkString(",")}", args)
156+
case invalid => invalidChoices(invalid)
148157
case _ => update(strings, args)
149158
case (StringTag, _) if argRest.nonEmpty || choices.exists(_.contains("")) =>
150159
setString(argRest, args)
@@ -287,6 +296,9 @@ object Settings:
287296
def MultiChoiceHelpSetting(name: String, helpArg: String, descr: String, choices: List[ChoiceWithHelp[String]], default: List[ChoiceWithHelp[String]], aliases: List[String] = Nil): Setting[List[ChoiceWithHelp[String]]] =
288297
publish(Setting(name, descr, default, helpArg, Some(choices), aliases = aliases))
289298

299+
def UncompleteMultiChoiceHelpSetting(name: String, helpArg: String, descr: String, choices: List[ChoiceWithHelp[String]], default: List[ChoiceWithHelp[String]], aliases: List[String] = Nil): Setting[List[ChoiceWithHelp[String]]] =
300+
publish(Setting(name, descr, default, helpArg, Some(choices), aliases = aliases, ignoreInvalidArgs = true))
301+
290302
def IntSetting(name: String, descr: String, default: Int, aliases: List[String] = Nil): Setting[Int] =
291303
publish(Setting(name, descr, default, aliases = aliases))
292304

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class CheckShadowing extends MiniPhase:
8383
ctx
8484

8585
override def prepareForOther(tree: tpd.Tree)(using Context): Context =
86-
importTraverser(tree.symbol).traverse(tree)
86+
importTraverser.traverse(tree)
8787
ctx
8888

8989
override def prepareForValDef(tree: tpd.ValDef)(using Context): Context =
@@ -152,7 +152,7 @@ class CheckShadowing extends MiniPhase:
152152
end nestedTypeTraverser
153153

154154
// To reach the imports during a miniphase traversal
155-
private def importTraverser(parent: Symbol) = new TreeTraverser:
155+
private def importTraverser = new TreeTraverser:
156156
import tpd._
157157

158158
override def traverse(tree: tpd.Tree)(using Context): Unit =

‎compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
291291
case UnusedSymbol(t, _, WarnTypes.PatVars) =>
292292
report.warning(s"unused pattern variable", t)
293293
case UnusedSymbol(t, _, WarnTypes.UnsetLocals) =>
294-
report.warning(s"unset local variable", t)
294+
report.warning(s"unset local variable, consider using an immutable val instead", t)
295295
case UnusedSymbol(t, _, WarnTypes.UnsetPrivates) =>
296-
report.warning(s"unset private variable", t)
296+
report.warning(s"unset private variable, consider using an immutable val instead", t)
297297
}
298298

299299
end CheckUnused

0 commit comments

Comments
 (0)
Please sign in to comment.