Skip to content

Commit 4259fd3

Browse files
committed
Clean up default arg
1 parent 7e5f63f commit 4259fd3

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import core.Contexts.*
77

88
import dotty.tools.io.{AbstractFile, Directory, JarArchive, PlainDirectory}
99

10-
import annotation.tailrec
1110
import annotation.internal.unshared
1211
import collection.mutable.ArrayBuffer
1312
import collection.mutable
@@ -107,7 +106,8 @@ object Settings:
107106

108107
def updateIn(state: SettingsState, x: Any): SettingsState = x match
109108
case _: T => state.update(idx, x)
110-
case _ => throw IllegalArgumentException(s"found: $x of type ${x.getClass.getName}, required: ${classTag[T]}")
109+
case null => throw IllegalArgumentException(s"attempt to set null ${classTag[T]}")
110+
case _ => throw IllegalArgumentException(s"found: $x of type ${x.getClass.getName}, required: ${classTag[T]}")
111111

112112
def isDefaultIn(state: SettingsState): Boolean = valueIn(state) == default
113113

@@ -172,10 +172,10 @@ object Settings:
172172
if ignoreInvalidArgs then state.warn(s"$msg, the tag was ignored") else state.fail(msg)
173173

174174
def isEmptyDefault = default == null.asInstanceOf[T] || classTag[T].match
175-
case ListTag => default.asInstanceOf[List[?]].isEmpty
175+
case ListTag => default.asInstanceOf[List[?]].isEmpty
176176
case StringTag => default.asInstanceOf[String].isEmpty
177177
case OptionTag => default.asInstanceOf[Option[?]].isEmpty
178-
case _ => false
178+
case _ => false
179179

180180
def setBoolean(argValue: String, args: List[String]) =
181181
if argValue.equalsIgnoreCase("true") || argValue.isEmpty then update(true, argValue, args)
@@ -240,15 +240,17 @@ object Settings:
240240
else if isEmptyDefault then
241241
missingArg
242242
else
243-
doSetArg(arg = null, args)
243+
doSetArg(arg = null, args) // update with default
244244

245-
def doSetArg(arg: String, argsLeft: List[String]) =
245+
def doSetArg(arg: String | Null, argsLeft: List[String]) =
246246
classTag[T] match
247247
case ListTag if arg == null =>
248-
update(default, arg, argsLeft)
248+
update(default, argStringValue = "", argsLeft)
249249
case ListTag =>
250250
val strings = arg.split(",").toList
251251
appendList(strings, arg, argsLeft)
252+
case _ if arg == null =>
253+
missingArg
252254
case StringTag =>
253255
setString(arg, argsLeft)
254256
case OutputTag =>
@@ -264,10 +266,10 @@ object Settings:
264266
missingArg
265267

266268
def matches(argName: String): Boolean =
267-
(allFullNames).exists(_ == argName.takeWhile(_ != ':')) || prefix.exists(arg.startsWith)
269+
allFullNames.exists(_ == argName.takeWhile(_ != ':')) || prefix.exists(arg.startsWith)
268270

269271
def argValRest: String =
270-
if(prefix.isEmpty) arg.dropWhile(_ != ':').drop(1) else arg.drop(prefix.get.length)
272+
if prefix.isEmpty then arg.dropWhile(_ != ':').drop(1) else arg.drop(prefix.get.length)
271273

272274
if matches(arg) then
273275
deprecation match
@@ -356,7 +358,6 @@ object Settings:
356358
*
357359
* to get their arguments.
358360
*/
359-
@tailrec
360361
final def processArguments(state: ArgsSummary, processAll: Boolean, skipped: List[String]): ArgsSummary =
361362
def stateWithArgs(args: List[String]) = ArgsSummary(state.sstate, args, state.errors, state.warnings)
362363
state.arguments match
@@ -365,11 +366,11 @@ object Settings:
365366
case "--" :: args =>
366367
checkDependencies(stateWithArgs(skipped ++ args))
367368
case x :: _ if x startsWith "-" =>
368-
@tailrec def loop(settings: List[Setting[?]]): ArgsSummary = settings match
369-
case setting :: settings1 =>
369+
def loop(settings: List[Setting[?]]): ArgsSummary = settings match
370+
case setting :: settings =>
370371
val state1 = setting.tryToSet(state)
371372
if state1 ne state then state1
372-
else loop(settings1)
373+
else loop(settings)
373374
case Nil =>
374375
state.warn(s"bad option '$x' was ignored")
375376
processArguments(loop(allSettings.toList), processAll, skipped)
@@ -379,7 +380,7 @@ object Settings:
379380
end processArguments
380381

381382
def processArguments(arguments: List[String], processAll: Boolean, settingsState: SettingsState = defaultState): ArgsSummary =
382-
processArguments(ArgsSummary(settingsState, arguments, Nil, Nil), processAll, Nil)
383+
processArguments(ArgsSummary(settingsState, arguments, errors = Nil, warnings = Nil), processAll, skipped = Nil)
383384

384385
def publish[T](settingf: Int => Setting[T]): Setting[T] =
385386
val setting = settingf(_allSettings.length)

0 commit comments

Comments
 (0)