From afc33571e839ff3bcb4b097f4b3021be40284c21 Mon Sep 17 00:00:00 2001 From: Brice Jaglin Date: Wed, 28 Feb 2024 22:40:32 +0100 Subject: [PATCH] support -Xsource:3-cross introduced in Scala 2.13.13 --- .../src/main/scala/scalafix/internal/v1/Args.scala | 4 +++- .../scalafix/internal/rule/OrganizeImports.scala | 1 + .../tests/interfaces/ScalafixArgumentsSuite.scala | 12 +++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scalafix-cli/src/main/scala/scalafix/internal/v1/Args.scala b/scalafix-cli/src/main/scala/scalafix/internal/v1/Args.scala index b68320433..e10680331 100644 --- a/scalafix-cli/src/main/scala/scalafix/internal/v1/Args.scala +++ b/scalafix-cli/src/main/scala/scalafix/internal/v1/Args.scala @@ -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 diff --git a/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala b/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala index 6a0aff93f..c67e8758f 100644 --- a/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala +++ b/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala @@ -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) diff --git a/scalafix-tests/integration/src/test/scala/scalafix/tests/interfaces/ScalafixArgumentsSuite.scala b/scalafix-tests/integration/src/test/scala/scalafix/tests/interfaces/ScalafixArgumentsSuite.scala index 58860c05f..cc264abc1 100644 --- a/scalafix-tests/integration/src/test/scala/scalafix/tests/interfaces/ScalafixArgumentsSuite.scala +++ b/scalafix-tests/integration/src/test/scala/scalafix/tests/interfaces/ScalafixArgumentsSuite.scala @@ -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 @@ -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") {