The Scala 3 compiler provides some helpful utilities to ease the migration.
Try running scalac
to have a glimpse of those utilities:
scalac
is the executable of the Scala compiler, it can be downloaded from Github.It can also be installed using Coursier with
cs install scala3-compiler
, in which casescalac
is aliasedscala3-compiler
.
Migration mode
The -source:3.0-migration
option makes the compiler forgiving on most of the dropped features, printing warnings in place of errors.
Each warning is a strong indication that the compiler is even capable of safely rewriting the deprecated pieces of code into their cross-compiling counterparts.
We call this the Scala 3 migration compilation.
Automatic rewrites
Once your code compiles in the migration mode, almost all warnings can be resolved automatically by the compiler itself.
To do so you just need to compile again, this time with the -source:3.0-migration
and the -rewrite
options.
Beware that the compiler will modify the code! It is intended to be safe. However you may want to commit the initial state so that you can print the diff applied by the compiler and revert it if necessary.
Good to know
- The rewrites are not applied if the code compiles in error.
- You cannot choose which rules are applied, the compiler runs all of them.
You can refer to the Incompatibility Table to see the list of Scala 3 migration rewrites.
Error explanations
The -source:3.0-migration
mode handles many of the changed features but not all of them.
The compiler can give you more details about the remaining errors when invoked with the -explain
and/or the -explain-types
options.
The
-explain
and-explain-types
options are not limited to the migration. They can, in general, assist you to learn and code in Scala 3.
Contributors to this page:
Contents
- Compatibility Reference
- Source Level
- Classpath Level
- Runtime
- Metaprogramming
- Tour of the Migration Tools
- Scala 2 with -Xsource:3
- Scala 3 Migration Mode
- Migration Tutorial
- Prerequisites
- Porting an sbt Project (using sbt-scala3-migrate)
- Porting an sbt Project (by hand)
- Cross-Building a Macro Library
- Mixing Scala 2.13 and Scala 3 Macros
- Scala 3 Syntax Rewriting
- Incompatibility Table
- Syntactic Changes
- Dropped Features
- Contextual Abstractions
- Other Changed Features
- Type Checker
- Type Inference
- Compiler Options
- Compiler Options Lookup Table
- New Compiler Options
- Scaladoc settings compatibility between Scala2 and Scala3
- Compiler Plugins
- Kind Projector Migration
- External Resources