From 363c0d62d96263107344e909b5c40fd144f8a2c9 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 6 Aug 2021 15:22:59 +0100 Subject: [PATCH 1/2] Allow IntSetting's to be set with a colon For example "-pagewidth:100" instead of the two arg "-pagewidth 100". --- compiler/src/dotty/tools/dotc/config/Settings.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/config/Settings.scala b/compiler/src/dotty/tools/dotc/config/Settings.scala index 98ed48ae8065..59d6e638f98d 100644 --- a/compiler/src/dotty/tools/dotc/config/Settings.scala +++ b/compiler/src/dotty/tools/dotc/config/Settings.scala @@ -130,7 +130,8 @@ object Settings: val output = if (isJar) JarArchive.create(path) else new PlainDirectory(path) update(output, args) } - case (IntTag, arg2 :: args2) => + case (IntTag, _) => + val arg2 :: args2 = if (argRest == "") args else argRest :: args try { val x = arg2.toInt choices match { From 38a27dbff39c372bf904e2736764a281145f5121 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 11 Aug 2021 09:17:54 +0100 Subject: [PATCH 2/2] Add a test for IntSetting's setting with a colon --- compiler/test/dotty/tools/dotc/SettingsTests.scala | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compiler/test/dotty/tools/dotc/SettingsTests.scala b/compiler/test/dotty/tools/dotc/SettingsTests.scala index 8369f6f77caa..4625f4f34f72 100644 --- a/compiler/test/dotty/tools/dotc/SettingsTests.scala +++ b/compiler/test/dotty/tools/dotc/SettingsTests.scala @@ -165,6 +165,18 @@ class SettingsTests { assertEquals(expectedErrors, summary.errors) } + @Test def `Allow IntSetting's to be set with a colon`: Unit = + object Settings extends SettingGroup: + val foo = IntSetting("-foo", "foo", 80) + import Settings._ + + val args = List("-foo:100") + val summary = processArguments(args, processAll = true) + assertTrue(s"Setting args errors:\n ${summary.errors.take(5).mkString("\n ")}", summary.errors.isEmpty) + withProcessedArgs(summary) { + assertEquals(100, foo.value) + } + private def withProcessedArgs(summary: ArgsSummary)(f: SettingsState ?=> Unit) = f(using summary.sstate) extension [T](setting: Setting[T])