Skip to content

Commit 00aff7c

Browse files
committed
processArgs is final for some tailrec
1 parent e2e77b5 commit 00aff7c

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,28 +221,26 @@ object Settings {
221221
*
222222
* to get their arguments.
223223
*/
224-
def processArguments(state: ArgsSummary, processAll: Boolean, skipped: List[String]): ArgsSummary = {
224+
final def processArguments(state: ArgsSummary, processAll: Boolean, skipped: List[String]): ArgsSummary =
225225
def stateWithArgs(args: List[String]) = ArgsSummary(state.sstate, args, state.errors, state.warnings)
226-
state.arguments match {
226+
state.arguments match
227227
case Nil =>
228228
checkDependencies(stateWithArgs(skipped))
229229
case "--" :: args =>
230230
checkDependencies(stateWithArgs(skipped ++ args))
231231
case x :: _ if x startsWith "-" =>
232-
@tailrec def loop(settings: List[Setting[?]]): ArgsSummary = settings match {
232+
@tailrec def loop(settings: List[Setting[?]]): ArgsSummary = settings match
233233
case setting :: settings1 =>
234234
val state1 = setting.tryToSet(state)
235-
if (state1 ne state) processArguments(state1, processAll, skipped)
235+
if state1 ne state then processArguments(state1, processAll, skipped)
236236
else loop(settings1)
237237
case Nil =>
238238
processArguments(state.warn(s"bad option '$x' was ignored"), processAll, skipped)
239-
}
240239
loop(allSettings.toList)
241240
case arg :: args =>
242-
if (processAll) processArguments(stateWithArgs(args), processAll, skipped :+ arg)
241+
if processAll then processArguments(stateWithArgs(args), processAll, skipped :+ arg)
243242
else state
244-
}
245-
}
243+
end processArguments
246244

247245
def processArguments(arguments: List[String], processAll: Boolean, settingsState: SettingsState = defaultState): ArgsSummary =
248246
processArguments(ArgsSummary(settingsState, arguments, Nil, Nil), processAll, Nil)

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ class SettingsTests {
5454
assertEquals(1, Settings.bar.value)
5555
}
5656

57+
@Test def `workaround dont crash on many files`: Unit =
58+
object Settings extends SettingGroup
59+
60+
inContext {
61+
val args = "--" :: List.fill(6000)("file.scala")
62+
val summary = Settings.processArguments(args, true)
63+
assertTrue(summary.errors.isEmpty)
64+
assertEquals(6000, summary.arguments.size)
65+
}
66+
67+
@Test def `dont crash on many files`: Unit =
68+
object Settings extends SettingGroup
69+
70+
inContext {
71+
val args = List.fill(6000)("file.scala")
72+
val summary = Settings.processArguments(args, true)
73+
assertTrue(summary.errors.isEmpty)
74+
assertEquals(6000, summary.arguments.size)
75+
}
76+
5777
@Test def validateChoices: Unit =
5878
object Settings extends SettingGroup:
5979
val foo = ChoiceSetting("-foo", "foo", "Foo", List("a", "b"), "a")

0 commit comments

Comments
 (0)