Skip to content

Commit

Permalink
improvement: Don't add release flag for versions from 17
Browse files Browse the repository at this point in the history
And also filter out if it exists.

I noticed some issues with Scala 2.13.15 and I am not sure how to work around it. This can be worked around if the user needs it as Metals does work with 17 and up.

For reference:
- scala/bug#13045
- #5272
  • Loading branch information
tgodzik committed Oct 29, 2024
1 parent 6453328 commit 654e5ae
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,40 @@ class CompilerConfiguration(
} yield jvmVersion.major

releaseVersion match {
case Some(version) =>
// https://github.com/scala/bug/issues/13045
case Some(version)
if version < 17 && scalaTarget.scalaBinaryVersion == "2.13" =>
/* Filter out -target: and -Xtarget: options, since they are not relevant and
* might interfere with -release option */
val filterOutTarget = scalacOptions.filterNot(opt =>
opt.startsWith("-target:") || opt.startsWith("-Xtarget:")
)
filterOutTarget ++ List("-release", version.toString())
case _ => scalacOptions
case _ if scalaTarget.scalaBinaryVersion == "2.13" =>
removeReleaseOptions(scalacOptions)
case _ =>
scalacOptions
}
}
}

private def isHigherThan17(version: String) =
Try(version.toInt).toOption.exists(_ >= 17)

private def removeReleaseOptions(options: Seq[String]): Seq[String] = {
options match {
case "-release" :: version :: tail if isHigherThan17(version) =>
removeReleaseOptions(tail)
case opt :: tail
if opt.startsWith("-release") && isHigherThan17(
opt.stripPrefix("-release:")
) =>
removeReleaseOptions(tail)
case head :: tail => head +: removeReleaseOptions(tail)
case Nil => options
}
}

private def log: List[String] =
if (config.initialConfig.compilers.debug) {
List(
Expand Down

0 comments on commit 654e5ae

Please sign in to comment.