An incompatibility is a piece of code that can be compiled with Scala 2.13 but not with Scala 3. Migrating a codebase involves finding and fixing all the incompatibilities of the source code. On rare occasions we can also have a runtime incompatibility: a piece of code that behaves differently at runtime.
In this page we propose a classification of the known incompatibilities. Each incompatibility is described by:
Scala 2.13 deprecations and feature warningsRun the 2.13 compilation with
-Xsource:3
to locate those incompatibilities in the code.
Scala 3 migration versus Scalafix rewritesSyntactic ChangesThe Scala 3 migration mode comes out-of-the-box. On the contrary, Scalafix is a tool that must be installed and configured manually. However Scalafix has its own advantages:
- It runs on Scala 2.13.
- It is composed of individual rules that you can apply one at a time.
- It is easily extensible by adding custom rules.
Some of the old syntax is not supported anymore.
Dropped FeaturesSome features are dropped to simplify the language.
Contextual AbstractionsThe redesign of contextual abstractions brings some well defined incompatibilities.
Furthermore we have changed the implicit resolution rules so that they are more useful and less surprising. The new rules are described here.
Because of these changes, the Scala 3 compiler could possibly fail at resolving some implicit parameters of existing Scala 2.13 code.
Other Changed FeaturesSome other features are simplified or restricted to make the language easier, safer or more consistent.
Type CheckerThe Scala 2.13 type checker is unsound in some specific cases. This can lead to surprising runtime errors in places we would not expect. Scala 3 being based on stronger theoretical foundations, these unsoundness bugs in the type checker are now fixed.
Type InferenceSome specific type inference rules have changed between Scala 2.13 and Scala 3.
Also we have improved the type inference algorithm by redesigning it entirely. This fundamental change leads to a few incompatibilities:
MacrosIt is always good practice to write the result types of all public values and methods explicitly. It prevents the public API of your library from changing with the Scala version, because of different inferred types.
This can be done prior to the Scala 3 migration by using the ExplicitResultTypes rule in Scalafix.
The Scala 3 compiler is not able to expand Scala 2.13 macros. Under such circumstances it is necessary to re-implement the Scala 2.13 macros using the new Scala 3 metaprogramming features.
You can go back to the Metaprogramming page to learn about the new metaprogramming features.
Contributors to this page:RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4