Skip to content

Commit 740fc6e

Browse files
committed
Warn if int setting is multiply set
1 parent 98845ef commit 740fc6e

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
@@ -110,7 +110,10 @@ object Settings:
110110
choices match
111111
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)
112112
case Some(xs) if !xs.contains(x) => fail(s"$argValue is not a valid choice for $name", args)
113-
case _ => update(x, args)
113+
case _ =>
114+
val dubious = changed && x != valueIn(sstate).asInstanceOf[Int]
115+
val updated = update(x, args)
116+
if dubious then updated.warn(s"Option $name was updated") else updated
114117
catch case _: NumberFormatException => fail(s"$argValue is not an integer argument for $name", args)
115118

116119
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
@@ -216,6 +216,15 @@ class SettingsTests {
216216
assertFalse("Multiple conflicting options is a warning", summary.warnings.isEmpty)
217217
assertTrue(summary.warnings.forall(_.contains("updated")))
218218

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

0 commit comments

Comments
 (0)