|
| 1 | +--- |
| 2 | +category: release |
| 3 | +permalink: /news/3.8.2/ |
| 4 | +title: "Scala 3.8.2 is now available!" |
| 5 | +by: Wojciech Mazur, VirtusLab |
| 6 | +--- |
| 7 | +# Scala 3.8.2 is now available! |
| 8 | + |
| 9 | +## Release highlights |
| 10 | + |
| 11 | +### Warning for `for` with many `val`s and overloaded `map` ([#25090](https://github.com/scala/scala3/pull/25090)) |
| 12 | + |
| 13 | +Scala 3.8’s **betterFors** (available since 3.7 under `-preview`) changes for-comprehension desugaring and removes an intermediate `map` used for consecutive `val` bindings. |
| 14 | + |
| 15 | +The following code snippet behaves differently at runtime depending on Scala version used for compilation. In Scala 3.7.x and earlier it produces `List((43,29), (43,30), (43,31))`, but starting with 3.8 it results in `Map(43 -> 31)`. |
| 16 | + |
| 17 | +```scala |
| 18 | +def f(x: Int): (Int, Int) = (1, x) |
| 19 | + |
| 20 | +val result: Iterable[(Int, Int)] = |
| 21 | + for // warning: For comprehension with multiple val assignments may change result type |
| 22 | + (k, v) <- Map(1 -> 1, 2 -> 1, 3 -> 1) |
| 23 | + x = k + v |
| 24 | + (a, b) = f(x) |
| 25 | + (y, z) <- Map(42 -> 27) |
| 26 | + yield (a + y, b + z) |
| 27 | +``` |
| 28 | + |
| 29 | +- **Before (3.7):** A synthetic tuple-producing `map` was inserted; that step could make `Map` select a generic `map` overload and become an `Iterable` (e.g. `List`) |
| 30 | +- **In 3.8:** That synthetic step is removed, so the conversion no longer happens and a different `map`/`flatMap` path can be selected. |
| 31 | + |
| 32 | +The previous runtime behaviour can be achived by explicitly converting first `Map` to `Iterable` type or by compilation with `-source:3.7` settings. |
| 33 | + |
| 34 | +The new warning highlights code where this migration risk exists. |
| 35 | + |
| 36 | +## Notable changes |
| 37 | + |
| 38 | +- Support `:dep ...` to add library dependencies in the Scala REPL [#24131](https://github.com/scala/scala3/pull/24131) |
| 39 | + |
| 40 | +- Upgrade to Scala.js 1.20.2 [#24898](https://github.com/scala/scala3/pull/24898) |
| 41 | + |
| 42 | +- Bump Scala CLI to v1.12.2 (was v1.11.0) [#25217](https://github.com/scala/scala3/pull/25217): |
| 43 | + New aliases for RC and nightly Scala versions. |
| 44 | + See the Scala CLI release notes for additional details: |
| 45 | + [v1.12.0](https://github.com/VirtusLab/scala-cli/releases/tag/v1.12.0), |
| 46 | + [v1.12.1](https://github.com/VirtusLab/scala-cli/releases/tag/v1.12.1) and |
| 47 | + [v1.12.2](https://github.com/VirtusLab/scala-cli/releases/tag/v1.12.2) |
| 48 | + |
| 49 | +For the complete list of changes and contributor credits, see the [release notes on GitHub](https://github.com/scala/scala3/releases/tag/3.8.2). |
0 commit comments