Skip to content

Commit 2c9f440

Browse files
Scala 2 vs Scala 3 doc added
1 parent f5f3938 commit 2c9f440

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Divergences between Scala 2 and Dotty
2+
The following issues encountered when compiling Scala 2 code as-is under Dotty:
3+
4+
## Scalafix candidates
5+
- If a method is defined `toSet()`, it cannot be called `toSet`.
6+
- “result type of implicit definition needs to be given explicitly”
7+
- There are no `'Symbol`s in Scala 3, you must construct symbols via `new Symbol("foo")` instead of old `'foo`
8+
9+
## Trivial
10+
- Scala 2.13 libraries cannot be used from Dotty, because the type signatures have Scala version `5.3` but `5.0` is expected.
11+
- To use Scala 2.12 dependencies from SBT with Dotty, explicitly suffix their names with `_2.12`.
12+
- Feature warnings about implicits `scala.language.implicitConversions` are output by default, unlike in Scala 2. This creates noise. Unclear how to turn off.
13+
14+
Implicit conversions must be applied explicitly:
15+
16+
```scala
17+
implicit def IterablePath[T](s: Iterable[T])(implicit conv: T => RelPath): RelPath = {
18+
s.foldLeft(rel){_ / conv(_)}
19+
}
20+
```
21+
22+
Stronger compile time guarantees on variance. Scala 2 does not assert variance on default parameters to parameters of the function value type. E.g. in geny:
23+
24+
```Scala
25+
# Dotty
26+
def count(f: A => Boolean = (a: A) => true): Int =
27+
| ^^^^^^^^^^^^^^
28+
|covariant type A occurs in contravariant position in type => A => Boolean of method count$default$1
29+
```
30+
31+
Fix:
32+
```Scala
33+
# Dotty
34+
def count[B >: A](f: B => Boolean = (_: B) => true): Int =
35+
```
36+
37+
## Tricky
38+
- Scala 3 macros are completely different from Scala 2 ones, requires a migration strategy of its own

0 commit comments

Comments
 (0)