Can/should I use both -Xsource:3
and -source:3.0-migration
in a cross-compiled codebase?
#17591
-
I'd like to refresh the compiler flags configured by sbt-typelevel which is used to cross-compile several libraries for both Scala 2 and 3. I have a question about:
Ref: https://docs.scala-lang.org/scala3/guides/migration/tooling-tour.html Does it make sense to use both of these flags in a cross-compiled codebase? I ask, because the former sounds like "make Scala 2 accept Scala 3-ish sources" and the latter sounds like "make Scala 3 accept Scala 2-ish sources". So I wonder if we should pick one strategy (aim for either Scala 2-ish or Scala 3-ish sources) and use the one flag that makes sense for that. Also what about Case StudyConsider the following program: case class Foo private (bar: String)
object Main {
def main(args: Array[String]): Unit =
println(Foo("bar"))
} Actually, this doesn't compile out-of-the-box with Scala 3.3.0.
Now here is what happens with various Scala version and compiler flag configurations:
Analysis:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
There is an old ticket somewhere to document The purpose of |
Beta Was this translation helpful? Give feedback.
-
I don't think a plugin should unilaterally touch -source, since it can lead to a lot of confusion down the road without the user realizing what the culprit is. For example -source:3.0-migration can break Scala 3 code because it changes implicit resolution rules (e.g., nested implicits will lead to ambiguity errors, but Scala 3 APIs using context function types routinely rely on that). |
Beta Was this translation helpful? Give feedback.
If you're cross-compiling, then I think -Xsource:3 isn't a problem because the things it reject will also be rejected by Scala 3 anyway, and it will mean you can use new syntax, but it's not a big deal either way.