Skip to content

Commit

Permalink
bugfix: Fix duplicate options detection
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tgodzik committed Sep 5, 2024
1 parent dd1a859 commit 614b836
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
22 changes: 18 additions & 4 deletions modules/build/src/test/scala/scala/build/tests/BuildTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,24 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {
}

test("cli scalac options shadowing using directives") {
val cliScalacOptions = Seq("-Xmaxwarns", "4", "-g:source")
val usingDirectiveScalacOptions = Seq("-nobootcp", "-Xmaxwarns", "5", "-g:none")
val cliScalacOptions = Seq("-Xmaxwarns", "4", "-g:source", "-language:no2AutoTupling")
val usingDirectiveScalacOptions = Seq(
"-nobootcp",
"-Xmaxwarns",
"5",
"-g:none",
"-language:no2AutoTupling",
"-language:strictEquality"
)

val expectedOptions = Seq("-Xmaxwarns", "4", "-g:source", "-nobootcp")
val expectedOptions = Seq(
"-Xmaxwarns",
"4",
"-g:source",
"-language:no2AutoTupling",
"-nobootcp",
"-language:strictEquality"
)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ final case class ScalacOpt(value: String) {
else Some("@").filter(value.startsWith)

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

object ScalacOpt {
Expand Down

0 comments on commit 614b836

Please sign in to comment.