Skip to content

Commit 614b836

Browse files
committed
bugfix: Fix duplicate options detection
Fixes #2708 Previously, for some of the options we would not deduplicate at all instead of using the full value. Now, for keys that can be added multiple times with different values we deduplicate the full option.
1 parent dd1a859 commit 614b836

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

modules/build/src/test/scala/scala/build/tests/BuildTests.scala

+18-4
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,24 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {
625625
}
626626

627627
test("cli scalac options shadowing using directives") {
628-
val cliScalacOptions = Seq("-Xmaxwarns", "4", "-g:source")
629-
val usingDirectiveScalacOptions = Seq("-nobootcp", "-Xmaxwarns", "5", "-g:none")
628+
val cliScalacOptions = Seq("-Xmaxwarns", "4", "-g:source", "-language:no2AutoTupling")
629+
val usingDirectiveScalacOptions = Seq(
630+
"-nobootcp",
631+
"-Xmaxwarns",
632+
"5",
633+
"-g:none",
634+
"-language:no2AutoTupling",
635+
"-language:strictEquality"
636+
)
630637

631-
val expectedOptions = Seq("-Xmaxwarns", "4", "-g:source", "-nobootcp")
638+
val expectedOptions = Seq(
639+
"-Xmaxwarns",
640+
"4",
641+
"-g:source",
642+
"-language:no2AutoTupling",
643+
"-nobootcp",
644+
"-language:strictEquality"
645+
)
632646

633647
val inputs = TestInputs(
634648
os.rel / "foo.scala" ->
@@ -650,7 +664,7 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {
650664
assert(maybeBuild.isRight)
651665
val build = maybeBuild.toOption.get
652666
val scalacOptions = build.options.scalaOptions.scalacOptions.toSeq.map(_.value.value)
653-
expect(scalacOptions == expectedOptions)
667+
assertEquals(scalacOptions, expectedOptions)
654668
}
655669
}
656670

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ final case class ScalacOpt(value: String) {
88
else Some("@").filter(value.startsWith)
99

1010
/** @return raw key for the option (only if the key can be shadowed from the CLI) */
11-
private[options] def shadowableKey: Option[String] =
12-
key.filterNot(key => ScalacOpt.repeatingKeys.exists(_.startsWith(key)))
11+
private[options] def shadowableKey: Option[String] = key match
12+
case Some(key) if ScalacOpt.repeatingKeys.exists(_.startsWith(key)) => Some(value)
13+
case otherwise => otherwise
1314
}
1415

1516
object ScalacOpt {

0 commit comments

Comments
 (0)