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

Allow shading of single-choice compiler options from the command line regardless of -/-- prefix #3279

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ abstract class ScalaCommand[T <: HasGlobalOptions](implicit myParser: Parser[T],
sharedOptions(options).foreach { so =>
val scalacOpts = so.scalacOptions.toScalacOptShadowingSeq
scalacOpts.keys
.find(k =>
k == ScalacOpt(s"-$YScriptRunnerOption") || k == ScalacOpt(s"--$YScriptRunnerOption")
)
.find(_.value.noDashPrefixes == YScriptRunnerOption)
.map(_.value)
.foreach(k =>
logger.message(LegacyScalaOptions.yScriptRunnerWarning(k, scalacOpts.getOption(k)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,36 @@ trait CompileScalacCompatTestDefinitions { _: CompileTestDefinitions =>
}
}
}

{
val prefixes = Seq("-", "--")
for {
prefix1 <- prefixes
prefix2 <- prefixes
optionKey = "Werror"
option1 = prefix1 + optionKey
option2 = prefix2 + optionKey
if actualScalaVersion.startsWith("3")
} test(
s"allow to override $option1 compiler option passed via directive by passing $option2 from the command line"
) {
val file = "example.scala"
TestInputs(os.rel / file ->
s"""//> using options -Wunused:all $option1
|@main def main() = {
| val unused = ""
| println("Hello, world!")
|}
|""".stripMargin).fromRoot { root =>
os.proc(
TestUtil.cli,
"compile",
file,
s"$option2:false",
extraOptions
)
.call(cwd = root, stderr = os.Pipe)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scala.build.options

import dependency.AnyDependency

import scala.build.options.ScalacOpt.noDashPrefixes
import scala.collection.mutable

/** Seq ensuring some of its values are unique according to some key */
Expand Down Expand Up @@ -31,10 +32,11 @@ final case class ShadowingSeq[T] private (values: Seq[Seq[T]]) {
for (group <- values.iterator ++ other.iterator) {
assert(group.nonEmpty)
val keyOpt = key.makeKey(group)
if (!keyOpt.exists(seen.contains)) {
if !keyOpt.exists(k => seen.contains(k.noDashPrefixes))
then {
l += group
for (key <- keyOpt)
seen += key
seen += key.noDashPrefixes
}
}

Expand Down
Loading