Skip to content

Commit

Permalink
Merge pull request #1943 from bjaglin/Xsource3cross
Browse files Browse the repository at this point in the history
support -Xsource:3-cross introduced in Scala 2.13.13
  • Loading branch information
bjaglin authored Feb 28, 2024
2 parents a005e01 + afc3357 commit 12fff17
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion scalafix-cli/src/main/scala/scalafix/internal/v1/Args.scala
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ case class Args(
}

def sourceScalaVersion: Option[ScalaVersion] =
extractLastScalacOption("-Xsource:").flatMap(ScalaVersion.from(_).toOption)
extractLastScalacOption("-Xsource:")
.map(_.stripSuffix("-cross"))
.flatMap(ScalaVersion.from(_).toOption)

def configureScalaVersions(
conf: ScalafixConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ object OrganizeImports {
// the pretty printer is just more permissive with the latest dialect.
val sourceScalaVersion =
extractSuffixForScalacOption("-Xsource:")
.map(_.stripSuffix("-cross"))
.flatMap(ScalaVersion.from(_).toOption)

scalaVersion.dialect(sourceScalaVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ class ScalafixArgumentsSuite extends AnyFunSuite with DiffAssertions {
assert(fileEvaluation.getErrorMessage.get.contains("SemanticDB not found"))
}

test("Scala2 source with Scala3 syntax can only be parsed with -Xsource:3") {
test(
"Scala2 source with Scala3 syntax can only be parsed with -Xsource:3 or -Xsource:3-cross"
) {
val cwd = StringFS
.string2dir(
s"""|/src/Scala2Source3.scala
Expand All @@ -388,6 +390,14 @@ class ScalafixArgumentsSuite extends AnyFunSuite with DiffAssertions {
.getFileEvaluations
.head
assert(withSource3.isSuccessful)

val withSource3cross =
args
.withScalacOptions(Collections.singletonList("-Xsource:3-cross"))
.evaluate()
.getFileEvaluations
.head
assert(withSource3cross.isSuccessful)
}

test("Source with Scala3 syntax can be parsed with dialect Scala3") {
Expand Down

0 comments on commit 12fff17

Please sign in to comment.