-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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.
All reactions
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.
Replies: 2 comments 9 replies
-
There is an old ticket somewhere to document -Xsource for Scala 2.
The purpose of -Xsource:3 was to get source in a place where it compiles straight under scala 3.
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
All reactions
-
and ideally it should only be used temporarily during a migration
Hmm, you mean like migrating from Scala 2 to Scala 3? What about for libraries that are permanently cross-compiled?
Beta Was this translation helpful? Give feedback.
All reactions
-
Such libraries need to be written in the common subset of Scala 2 and 3 which has the same meaning in both languages (and use version-specific sources when that's not possible).
Beta Was this translation helpful? Give feedback.
All reactions
-
Ok, thanks! So if I'm understanding correctly, cross-compiling libraries should use neither -Xsource:3 nor -source:3.x-migration ?
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
-
I disagree that -Xsource:3 doesn't matter. Modulo bugs, you can use leading infix. You can't use early defs. It was a bigger commitment when it included the implicits resolution change.
Beta Was this translation helpful? Give feedback.