Skip to content

Commit 654e5ae

Browse files
committed
improvement: Don't add release flag for versions from 17
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 - scalameta#5272
1 parent 6453328 commit 654e5ae

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scala

+24-2
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,40 @@ class CompilerConfiguration(
396396
} yield jvmVersion.major
397397

398398
releaseVersion match {
399-
case Some(version) =>
399+
// https://github.com/scala/bug/issues/13045
400+
case Some(version)
401+
if version < 17 && scalaTarget.scalaBinaryVersion == "2.13" =>
400402
/* Filter out -target: and -Xtarget: options, since they are not relevant and
401403
* might interfere with -release option */
402404
val filterOutTarget = scalacOptions.filterNot(opt =>
403405
opt.startsWith("-target:") || opt.startsWith("-Xtarget:")
404406
)
405407
filterOutTarget ++ List("-release", version.toString())
406-
case _ => scalacOptions
408+
case _ if scalaTarget.scalaBinaryVersion == "2.13" =>
409+
removeReleaseOptions(scalacOptions)
410+
case _ =>
411+
scalacOptions
407412
}
408413
}
409414
}
410415

416+
private def isHigherThan17(version: String) =
417+
Try(version.toInt).toOption.exists(_ >= 17)
418+
419+
private def removeReleaseOptions(options: Seq[String]): Seq[String] = {
420+
options match {
421+
case "-release" :: version :: tail if isHigherThan17(version) =>
422+
removeReleaseOptions(tail)
423+
case opt :: tail
424+
if opt.startsWith("-release") && isHigherThan17(
425+
opt.stripPrefix("-release:")
426+
) =>
427+
removeReleaseOptions(tail)
428+
case head :: tail => head +: removeReleaseOptions(tail)
429+
case Nil => options
430+
}
431+
}
432+
411433
private def log: List[String] =
412434
if (config.initialConfig.compilers.debug) {
413435
List(

0 commit comments

Comments
 (0)