From f49b27b4c8a8061a72dc6a830c1a67270e4289ee Mon Sep 17 00:00:00 2001 From: "John M. Higgins" Date: Sun, 3 Sep 2023 08:38:27 -0700 Subject: [PATCH] fix: Closes #18367 `-Wconf` options are processed incorrectly --- .../src/dotty/tools/dotc/reporting/WConf.scala | 2 +- .../tools/dotc/config/ScalaSettingsTests.scala | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/WConf.scala b/compiler/src/dotty/tools/dotc/reporting/WConf.scala index af1a5c0f0f47..5303ccd7f219 100644 --- a/compiler/src/dotty/tools/dotc/reporting/WConf.scala +++ b/compiler/src/dotty/tools/dotc/reporting/WConf.scala @@ -106,7 +106,7 @@ object WConf: def fromSettings(settings: List[String]): Either[List[String], WConf] = if (settings.isEmpty) Right(WConf(Nil)) else - val parsedConfs: List[Either[List[String], (List[MessageFilter], Action)]] = settings.map(conf => + val parsedConfs: List[Either[List[String], (List[MessageFilter], Action)]] = settings.reverse.map(conf => val filtersAndAction = conf.split(':') if filtersAndAction.length != 2 then Left(List("exactly one `:` expected (&...&:)")) else diff --git a/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala b/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala index 44cf83b521f4..a1014043724e 100644 --- a/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala +++ b/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala @@ -83,4 +83,18 @@ class ScalaSettingsTests: val nowr = new Diagnostic.Warning("This is a problem.".toMessage, util.NoSourcePosition) assertEquals(Action.Silent, sut.action(nowr)) + @Test def `i18367 rightmost WConf flags take precedence over flags to the left`: Unit = + import reporting.{Action, Diagnostic} + val sets = new ScalaSettings + val args = List("-Wconf:cat=deprecation:e", "-Wconf:cat=deprecation:s") + val sumy = ArgsSummary(sets.defaultState, args, errors = Nil, warnings = Nil) + val proc = sets.processArguments(sumy, processAll = true, skipped = Nil) + val conf = sets.Wconf.valueIn(proc.sstate) + val msg = "Don't use that!".toMessage + val depr = new Diagnostic.DeprecationWarning(msg, util.NoSourcePosition) + val sut = reporting.WConf.fromSettings(conf).getOrElse(???) + assertEquals(Action.Silent, sut.action(depr)) + + + end ScalaSettingsTests