Skip to content

Commit b07b550

Browse files
committed
Xsource:compat
1 parent e657879 commit b07b550

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

_overviews/scala3-migration/tooling-scala2-xsource3.md

+18-9
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,29 @@ This page explains the details behind the flags. An overview is shown using `sca
1717

1818
## Migration vs cross-building
1919

20-
With Scala 2.13.13 and newer, the `-Xsource:3` flag comes in two variants:
20+
With Scala 2.13.14 and newer, the `-Xsource:3` flag comes in three variants:
2121

22-
- `Xsource:3` enables warnings relevant for migrating a codebase to Scala 3.
22+
- `Xsource:3-migration` enables warnings relevant for migrating a codebase to Scala 3.
2323
In addition to new warnings, the flag enables certain benign Scala 3 syntaxes such as `import p.*`.
24-
- `Xsource:3-cross` is useful for projects that cross-build between Scala 2 and 3 for a longer period of time.
25-
For certain language constructs that trigger a warning with `-Xsource:3`, the behavior changes to match Scala 3.
24+
As a convenience, `Xsource:3` is an alias.
25+
- `Xsource:3-cross` is useful for projects that cross-build between Scala 2 and 3.
26+
Certain language constructs have been backported from Scala 3 in order to improve compatibility.
27+
- `Xsource:3-compat` restricts `3-cross` to binary compatible features. Other binary incompatible
28+
features can be added using `-Ysource-options`.
2629

2730
Details about individual warnings are listed below on this page.
2831

29-
## Fatal warnings and quick fixes
32+
## Warnings as errors, and quick fixes
3033

31-
By default, Scala 3 migration warnings emitted by Scala 2.13 are fatal, i.e., they are reported as errors.
32-
This can be changed using `-Wconf`, for example `-Wconf:cat=scala3-migration:w` changes them to be reported as warnings.
33-
Alternatively, `-Xmigration` has the same effect.
34+
By default, Scala 3 migration warnings emitted by Scala 2.13 are reported as errors,
35+
using the default configuration, `-Wconf:cat=scala3-migration:e`.
36+
That ensures that migration messaging is more visible.
37+
Diagnostics can be emitted as warnings by specifying `-Wconf:cat=scala3-migration:w`.
38+
Typically, emitting warnings instead of errors will cause more diagnostics to be reported,
39+
so that can be either informative or noisy.
3440

35-
The [`@nowarn` annotation](https://www.scala-lang.org/api/current/scala/annotation/nowarn.html) can be used to suppress individual warnings, which also works with fatal warnings enabled.
41+
The [`@nowarn` annotation](https://www.scala-lang.org/api/current/scala/annotation/nowarn.html) can be used to suppress individual warnings.
42+
Diagnostics are suppressed before they are promoted to errors, so the annotation works whatever the `-Wconf`.
3643

3744
The Scala 2.13 compiler implements quick fixes for many Scala 3 migration warnings.
3845
Quick fixes are displayed in Metals-based IDEs (not yet in IntelliJ), and they can be applied directly to the source code using the `-quickfix` flag, for example `-quickfix:cat=scala3-migration`.
@@ -83,6 +90,8 @@ It is possible to work around this using version-dependent source files, see [sc
8390

8491
Working around the case companion `FunctionN` parent change is currently difficult (Scala 2.13.13), a solution is being discussed at [scala/bug#12961](https://github.com/scala/bug/issues/12961).
8592

93+
Binary incompatible features can be used selectively under `-Xsource:3-compat` and `-Ysource-options` where the features can be enumerated.
94+
8695
### Changes in language semantics
8796

8897
The following table shows cases where `-Xsource:3-cross` adopts language feature semantics from Scala 3.

0 commit comments

Comments
 (0)