Skip to content

Commit ddd7734

Browse files
committed
Warn if int setting is multiply set
1 parent 2294533 commit ddd7734

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ object Settings:
111111
choices match
112112
case Some(r: Range) if x < r.head || r.last < x => fail(s"$argValue is out of legal range ${r.head}..${r.last} for $name", args)
113113
case Some(xs) if !xs.contains(x) => fail(s"$argValue is not a valid choice for $name", args)
114-
case _ => update(x, args)
114+
case _ =>
115+
val dubious = changed && x != valueIn(sstate).asInstanceOf[Int]
116+
val updated = update(x, args)
117+
if dubious then updated.warn(s"Option $name was updated") else updated
115118
catch case _: NumberFormatException => fail(s"$argValue is not an integer argument for $name", args)
116119

117120
def doSet(argRest: String): ArgsSummary = (summon[ClassTag[T]]: @unchecked) match {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ class SettingsTests {
218218
assertFalse("Multiple conflicting options is a warning", summary.warnings.isEmpty)
219219
assertTrue(summary.warnings.forall(_.contains("updated")))
220220

221+
@Test def `int option also warns`: Unit =
222+
object Settings extends SettingGroup:
223+
val option = IntSetting("-option", "Some option", 42)
224+
val args = List("-option:17", "-option:27")
225+
val summary = Settings.processArguments(args, processAll = true)
226+
assertTrue("Multiple options is not an error", summary.errors.isEmpty)
227+
assertFalse("Multiple conflicting options is a warning", summary.warnings.isEmpty)
228+
assertTrue(summary.warnings.forall(_.contains("updated")))
229+
221230
// use the supplied summary for evaluating settings
222231
private def withProcessedArgs(summary: ArgsSummary)(f: SettingsState ?=> Unit) = f(using summary.sstate)
223232

0 commit comments

Comments
 (0)