Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Fix duplicate options detection #3151

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading