Skip to content

Commit ae43a29

Browse files
committed
Make non-existent compiler options emit warnings instead of failing
1 parent 2f5b1f8 commit ae43a29

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ object CompilerCommand extends DotClass {
104104
else ""
105105
}
106106

107+
// Print all warnings encountered during arguments parsing
108+
summary.warnings.foreach(ctx.warning(_))
109+
107110
if (summary.errors.nonEmpty) {
108111
summary.errors foreach (ctx.error(_))
109112
ctx.echo(" dotc -help gives more information")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ object PathResolver {
144144
}
145145
else {
146146
implicit val ctx = (new ContextBase).initialCtx
147-
val ArgsSummary(sstate, rest, errors) =
147+
val ArgsSummary(sstate, rest, errors, warnings) =
148148
ctx.settings.processArguments(args.toList, true)
149149
errors.foreach(println)
150150
val pr = new PathResolver()(ctx.fresh.setSettings(sstate))

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class ScalaSettings extends Settings.SettingGroup {
2626
val explain = BooleanSetting("-explain", "Explain errors in more detail.")
2727
val feature = BooleanSetting("-feature", "Emit warning and location for usages of features that should be imported explicitly.")
2828
val help = BooleanSetting("-help", "Print a synopsis of standard options")
29-
// FIXME: `-nowarn` is not used in the compiler, but sbt passes this as an option
30-
val nowarn = BooleanSetting("-nowarn", "Generate no warnings.")
3129
val color = ChoiceSetting("-color", "mode", "Colored output", List("always", "never"/*, "auto"*/), "always"/* "auto"*/)
3230
val target = ChoiceSetting("-target", "target", "Target platform for object files. All JVM 1.5 targets are deprecated.",
3331
List("jvm-1.5", "jvm-1.5-fjbg", "jvm-1.5-asm", "jvm-1.6", "jvm-1.7", "jvm-1.8", "msil"), "jvm-1.8")

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ object Settings {
4444
case class ArgsSummary(
4545
sstate: SettingsState,
4646
arguments: List[String],
47-
errors: List[String]) {
47+
errors: List[String],
48+
warnings: List[String]) {
4849

4950
def fail(msg: String) =
50-
ArgsSummary(sstate, arguments, errors :+ msg)
51+
ArgsSummary(sstate, arguments.tail, errors :+ msg, warnings)
52+
53+
def warn(msg: String) =
54+
ArgsSummary(sstate, arguments.tail, errors, warnings :+ msg)
5155
}
5256

5357
case class Setting[T: ClassTag] private[Settings] (
@@ -106,11 +110,11 @@ object Settings {
106110
}
107111

108112
def tryToSet(state: ArgsSummary): ArgsSummary = {
109-
val ArgsSummary(sstate, arg :: args, errors) = state
113+
val ArgsSummary(sstate, arg :: args, errors, warnings) = state
110114
def update(value: Any, args: List[String]) =
111-
ArgsSummary(updateIn(sstate, value), args, errors)
115+
ArgsSummary(updateIn(sstate, value), args, errors, warnings)
112116
def fail(msg: String, args: List[String]) =
113-
ArgsSummary(sstate, args, errors :+ msg)
117+
ArgsSummary(sstate, args, errors :+ msg, warnings)
114118
def missingArg =
115119
fail(s"missing argument for option $name", args)
116120
def doSet(argRest: String) = ((implicitly[ClassTag[T]], args): @unchecked) match {
@@ -206,7 +210,7 @@ object Settings {
206210
* to get their arguments.
207211
*/
208212
protected def processArguments(state: ArgsSummary, processAll: Boolean, skipped: List[String]): ArgsSummary = {
209-
def stateWithArgs(args: List[String]) = ArgsSummary(state.sstate, args, state.errors)
213+
def stateWithArgs(args: List[String]) = ArgsSummary(state.sstate, args, state.errors, state.warnings)
210214
state.arguments match {
211215
case Nil =>
212216
checkDependencies(stateWithArgs(skipped))
@@ -219,7 +223,7 @@ object Settings {
219223
if (state1 ne state) processArguments(state1, processAll, skipped)
220224
else loop(settings1)
221225
case Nil =>
222-
state.fail(s"bad option: '$x'")
226+
processArguments(state.warn(s"bad option '$x' was ignored"), processAll, skipped)
223227
}
224228
loop(allSettings.toList)
225229
case arg :: args =>
@@ -229,7 +233,7 @@ object Settings {
229233
}
230234

231235
def processArguments(arguments: List[String], processAll: Boolean)(implicit ctx: Context): ArgsSummary =
232-
processArguments(ArgsSummary(ctx.sstate, arguments, Nil), processAll, Nil)
236+
processArguments(ArgsSummary(ctx.sstate, arguments, Nil, Nil), processAll, Nil)
233237

234238
def publish[T](settingf: Int => Setting[T]): Setting[T] = {
235239
val setting = settingf(_allSettings.length)

compiler/test/dotc/tests.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ class tests extends CompilerTest {
180180

181181
val negCustomArgs = negDir + "customArgs/"
182182

183-
@Test def neg_cli_error = compileFile(negCustomArgs, "cliError", List("-thisOptionDoesNotExist"))
184-
185183
@Test def neg_typers() = compileFile(negCustomArgs, "typers")(allowDoubleBindings)
186184
@Test def neg_overrideClass = compileFile(negCustomArgs, "overrideClass", scala2mode)
187185
@Test def neg_autoTupling = compileFile(negCustomArgs, "autoTuplingTest", args = "-language:noAutoTupling" :: Nil)

tests/neg/customArgs/cliError.scala

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)