Skip to content

Commit

Permalink
Allow shading of single-choice compiler options from the command line…
Browse files Browse the repository at this point in the history
… regardless of `-`/`--` prefix
  • Loading branch information
Gedochao committed Nov 14, 2024
1 parent 8e44678 commit 8941fa5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,34 @@ 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 script = "example.sc"
TestInputs(os.rel / script ->
s"""//> using options -Wunused:all $option1
|val unused = ""
|println("Hello, world!")
|""".stripMargin).fromRoot { root =>
os.proc(
TestUtil.cli,
"compile",
script,
s"$option2:false",
extraOptions
)
.call(cwd = root, stderr = os.Pipe)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8941fa5

Please sign in to comment.