Skip to content

Commit 7751341

Browse files
authored
Merge pull request #3245 from Gedochao/maintenance/repeating-wconf
Ensure consecutive `-Wconf:*` flags are not ignored
2 parents edd0516 + 9454f6e commit 7751341

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
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

+46
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,52 @@ class SipScalaTests extends ScalaCliSuite with SbtTestHelper with MillTestHelper
515515
}
516516
}
517517

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)") {
523+
val sv = "3.5.2"
524+
val sourceFileName = "example.scala"
525+
val warningConfOptions = Seq("-Wconf:cat=deprecation:e", "-Wconf:any:s")
526+
val maybeDirectiveString =
527+
if (useDirective) s"//> using options ${warningConfOptions.mkString(" ")}" else ""
528+
TestInputs(os.rel / sourceFileName ->
529+
s"""//> using scala $sv
530+
|$maybeDirectiveString
531+
|object WConfExample extends App {
532+
| @deprecated("This method will be removed", "1.0.0")
533+
| def oldMethod(): Unit = println("This is an old method.")
534+
| oldMethod()
535+
|}
536+
|""".stripMargin).fromRoot { root =>
537+
val localCache = root / "local-cache"
538+
val localBin = root / "local-bin"
539+
os.proc(
540+
TestUtil.cs,
541+
"install",
542+
"--cache",
543+
localCache,
544+
"--install-dir",
545+
localBin,
546+
s"scalac:$sv"
547+
).call(cwd = root)
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)
557+
val scalacRes = os.proc(localBin / "scalac", warningConfOptions, sourceFileName)
558+
.call(cwd = root, check = false, stderr = os.Pipe)
559+
expect(scalacRes.exitCode == cliRes.exitCode)
560+
expect(cliRes.err.trim() == scalacRes.err.trim())
561+
}
562+
}
563+
518564
for {
519565
sv <- Seq(Constants.scala212, Constants.scala213, Constants.scala3NextRc)
520566
code =

modules/options/src/main/scala/scala/build/options/ScalacOpt.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ object ScalacOpt {
1818
private val repeatingKeys = Set(
1919
"-Xplugin",
2020
"-P", // plugin options
21-
"-language"
21+
"-language",
22+
"-Wconf"
2223
)
2324

2425
implicit val hashedType: HashedType[ScalacOpt] = {

0 commit comments

Comments
 (0)