Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Is the scala 2 compiler compatible with scala 3?


Asked by Corey Vo on Dec 11, 2021 Scala



They are mostly source compatible, but differences exist. However: Scala 3 code can use Scala 2 artifacts because the Scala 3 compiler understands the classfile format for sources compiled with Scala 2.12 and upwards. Scala 3 and Scala 2 share the same standard library.
Indeed,
It’s worth emphasizing that Scala 2 and Scala 3 are fundamentally the same language. The compiler is new, but nearly everything Scala programmers already know about Scala 2 applies to Scala 3 as well, and most ordinary Scala 2 code will also work on Scala 3 with only minor changes.
Accordingly, Although Scala 2.11 and 2.12 are mostly source compatible to facilitate cross-building, they are not binary compatible. This allows us to keep improving the Scala compiler and standard library.
Moreover,
To recap, app is now compiled by Scala 3 and depends on shared , which is compiled by Scala 2.13. If we do sbt app/run we should see the app project recompile and it will run as before. Now lets try the other way around, in this case we also have to enable reading Scala 3 dependencies in Scala 2 with the flag -Ytasty-reader:
Likewise,
Use Scastie to run single-file Scala programs in your browser using multiple Scala compilers; the production Scala 2.x compilers, Scala.js, Scala 3, and Typelevel Scala. Save and share executable Scala code snippets. Or are you looking for previous releases of Scala?