Skip to content

Commit b11c250

Browse files
committed
Clean up default arg
1 parent 74ce349 commit b11c250

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
@@ -5,7 +5,6 @@ import core.Contexts.*
55

66
import dotty.tools.io.{AbstractFile, Directory, JarArchive, PlainDirectory}
77

8-
import annotation.tailrec
98
import annotation.internal.unshared
109
import collection.mutable.ArrayBuffer
1110
import collection.mutable
@@ -116,7 +115,8 @@ object Settings:
116115

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

121121
def isDefaultIn(state: SettingsState): Boolean = valueIn(state) == default
122122

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

183183
def isEmptyDefault = default == null.asInstanceOf[T] || classTag[T].match
184-
case ListTag => default.asInstanceOf[List[?]].isEmpty
184+
case ListTag => default.asInstanceOf[List[?]].isEmpty
185185
case StringTag => default.asInstanceOf[String].isEmpty
186186
case OptionTag => default.asInstanceOf[Option[?]].isEmpty
187-
case _ => false
187+
case _ => false
188188

189189
def setBoolean(argValue: String, args: List[String]) =
190190
if argValue.equalsIgnoreCase("true") || argValue.isEmpty then update(true, argValue, args)
@@ -254,15 +254,17 @@ object Settings:
254254
else if isEmptyDefault then
255255
missingArg
256256
else
257-
doSetArg(arg = null, args)
257+
doSetArg(arg = null, args) // update with default
258258

259-
def doSetArg(arg: String, argsLeft: List[String]) =
259+
def doSetArg(arg: String | Null, argsLeft: List[String]) =
260260
classTag[T] match
261261
case ListTag if arg == null =>
262-
update(default, arg, argsLeft)
262+
update(default, argStringValue = "", argsLeft)
263263
case ListTag =>
264264
val strings = arg.split(",").toList
265265
appendList(strings, arg, argsLeft)
266+
case _ if arg == null =>
267+
missingArg
266268
case StringTag =>
267269
setString(arg, argsLeft)
268270
case OutputTag =>
@@ -278,10 +280,10 @@ object Settings:
278280
missingArg
279281

280282
def matches(argName: String): Boolean =
281-
(allFullNames).exists(_ == argName.takeWhile(_ != ':')) || prefix.exists(arg.startsWith)
283+
allFullNames.exists(_ == argName.takeWhile(_ != ':')) || prefix.exists(arg.startsWith)
282284

283285
def argValRest: String =
284-
if(prefix.isEmpty) arg.dropWhile(_ != ':').drop(1) else arg.drop(prefix.get.length)
286+
if prefix.isEmpty then arg.dropWhile(_ != ':').drop(1) else arg.drop(prefix.get.length)
285287

286288
if matches(arg) then
287289
deprecation match
@@ -370,7 +372,6 @@ object Settings:
370372
*
371373
* to get their arguments.
372374
*/
373-
@tailrec
374375
final def processArguments(state: ArgsSummary, processAll: Boolean, skipped: List[String]): ArgsSummary =
375376
def stateWithArgs(args: List[String]) = ArgsSummary(state.sstate, args, state.errors, state.warnings)
376377
state.arguments match
@@ -379,11 +380,11 @@ object Settings:
379380
case "--" :: args =>
380381
checkDependencies(stateWithArgs(skipped ++ args))
381382
case x :: _ if x startsWith "-" =>
382-
@tailrec def loop(settings: List[Setting[?]]): ArgsSummary = settings match
383-
case setting :: settings1 =>
383+
def loop(settings: List[Setting[?]]): ArgsSummary = settings match
384+
case setting :: settings =>
384385
val state1 = setting.tryToSet(state)
385386
if state1 ne state then state1
386-
else loop(settings1)
387+
else loop(settings)
387388
case Nil =>
388389
state.warn(s"bad option '$x' was ignored")
389390
processArguments(loop(allSettings.toList), processAll, skipped)
@@ -393,7 +394,7 @@ object Settings:
393394
end processArguments
394395

395396
def processArguments(arguments: List[String], processAll: Boolean, settingsState: SettingsState = defaultState): ArgsSummary =
396-
processArguments(ArgsSummary(settingsState, arguments, Nil, Nil), processAll, Nil)
397+
processArguments(ArgsSummary(settingsState, arguments, errors = Nil, warnings = Nil), processAll, skipped = Nil)
397398

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

0 commit comments

Comments
 (0)