diff --git a/modules/integration/src/test/scala/scala/cli/integration/CompileScalacCompatTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/CompileScalacCompatTestDefinitions.scala index 872924ae58..a862818e58 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/CompileScalacCompatTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/CompileScalacCompatTestDefinitions.scala @@ -205,4 +205,36 @@ trait CompileScalacCompatTestDefinitions { _: CompileTestDefinitions => } } } + + { + val prefixes = Seq("-", "--") + for { + prefix1 <- prefixes + prefix2 <- prefixes + optionKey = "Werror" + option1 = prefix1 + optionKey + option2 = prefix2 + optionKey + if actualScalaVersion.startsWith("3") + } test( + s"allow to override $option1 compiler option passed via directive by passing $option2 from the command line" + ) { + val file = "example.scala" + TestInputs(os.rel / file -> + s"""//> using options -Wunused:all $option1 + |@main def main() = { + | val unused = "" + | println("Hello, world!") + |} + |""".stripMargin).fromRoot { root => + os.proc( + TestUtil.cli, + "compile", + file, + s"$option2:false", + extraOptions + ) + .call(cwd = root, stderr = os.Pipe) + } + } + } } diff --git a/modules/options/src/main/scala/scala/build/options/ShadowingSeq.scala b/modules/options/src/main/scala/scala/build/options/ShadowingSeq.scala index 1ff88b5daf..820c9fa844 100644 --- a/modules/options/src/main/scala/scala/build/options/ShadowingSeq.scala +++ b/modules/options/src/main/scala/scala/build/options/ShadowingSeq.scala @@ -31,7 +31,12 @@ final case class ShadowingSeq[T] private (values: Seq[Seq[T]]) { for (group <- values.iterator ++ other.iterator) { assert(group.nonEmpty) val keyOpt = key.makeKey(group) - if (!keyOpt.exists(seen.contains)) { + if !keyOpt.exists { + case k if k.startsWith("--") => seen.contains(k) || seen.contains(k.stripPrefix("-")) + case k if k.startsWith("-") => seen.contains(k) || seen.contains(s"-$k") + case k => seen.contains(k) + } + then { l += group for (key <- keyOpt) seen += key