Skip to content

Commit 9454f6e

Browse files
committed
Ensure compiler options passed via the command line and using directives follow the same order
1 parent cae9eeb commit 9454f6e

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

modules/cli/src/main/scala/scala/cli/commands/shared/ScalacOptions.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ object ScalacOptions {
101101
case h :: t
102102
if scalacOptionsPrefixes.exists(h.startsWith) &&
103103
!ScalacDeprecatedOptions.contains(h) =>
104-
Right(Some((Some(h :: acc.getOrElse(Nil)), t)))
104+
Right(Some((Some(acc.getOrElse(Nil) :+ h), t)))
105105
case h :: t if scalacNoArgAliasedOptions.contains(h) =>
106-
Right(Some((Some(h :: acc.getOrElse(Nil)), t)))
106+
Right(Some((Some(acc.getOrElse(Nil) :+ h), t)))
107107
case h :: t if scalacAliasedOptions.contains(h) =>
108108
// check if the next scalac arg is a different option or a param to the current option
109109
val maybeOptionArg = t.headOption.filter(!_.startsWith("-"))
110110
// if it's a param, it'll be treated as such and considered already parsed
111111
val newTail = maybeOptionArg.map(_ => t.drop(1)).getOrElse(t)
112112
val newHead = List(h) ++ maybeOptionArg
113-
Right(Some((Some(newHead ++ acc.getOrElse(Nil)), newTail)))
113+
Right(Some((Some(acc.getOrElse(Nil) ++ newHead), newTail)))
114114
case _ => underlying.step(args, index, acc, formatter)
115115
}
116116
def get(acc: Option[List[String]], formatter: Formatter[Name]): Either[Error, List[String]] =

modules/integration/src/test/scala/scala/cli/integration/SipScalaTests.scala

+18-5
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,19 @@ class SipScalaTests extends ScalaCliSuite with SbtTestHelper with MillTestHelper
515515
}
516516
}
517517

518-
test("consecutive -Wconf:* flags are not ignored") {
518+
for {
519+
useDirective <- Seq(true, false)
520+
if !Properties.isWin
521+
optionsSource = if (useDirective) "using directive" else "command line"
522+
} test(s"consecutive -Wconf:* flags are not ignored (passed via $optionsSource)") {
519523
val sv = "3.5.2"
520524
val sourceFileName = "example.scala"
521525
val warningConfOptions = Seq("-Wconf:cat=deprecation:e", "-Wconf:any:s")
526+
val maybeDirectiveString =
527+
if (useDirective) s"//> using options ${warningConfOptions.mkString(" ")}" else ""
522528
TestInputs(os.rel / sourceFileName ->
523529
s"""//> using scala $sv
524-
|//> using options ${warningConfOptions.mkString(" ")}
530+
|$maybeDirectiveString
525531
|object WConfExample extends App {
526532
| @deprecated("This method will be removed", "1.0.0")
527533
| def oldMethod(): Unit = println("This is an old method.")
@@ -539,12 +545,19 @@ class SipScalaTests extends ScalaCliSuite with SbtTestHelper with MillTestHelper
539545
localBin,
540546
s"scalac:$sv"
541547
).call(cwd = root)
542-
val cliRes = os.proc(TestUtil.cli, "compile", sourceFileName, "--server=false")
543-
.call(cwd = root, check = false, stderr = os.Pipe)
548+
val cliRes =
549+
os.proc(
550+
TestUtil.cli,
551+
"compile",
552+
sourceFileName,
553+
"--server=false",
554+
if (useDirective) Nil else warningConfOptions
555+
)
556+
.call(cwd = root, check = false, stderr = os.Pipe)
544557
val scalacRes = os.proc(localBin / "scalac", warningConfOptions, sourceFileName)
545558
.call(cwd = root, check = false, stderr = os.Pipe)
546559
expect(scalacRes.exitCode == cliRes.exitCode)
547-
expect(scalacRes.err.trim() == cliRes.err.trim())
560+
expect(cliRes.err.trim() == scalacRes.err.trim())
548561
}
549562
}
550563

0 commit comments

Comments
 (0)