|
| 1 | +--- |
| 2 | +layout: blog-page |
| 3 | +title: Scala 3.0.1 and 3.0.2-RC1 are here! |
| 4 | +author: Michał Pałka |
| 5 | +authorImg: /images/michal.jpg |
| 6 | +date: 2021-07-19 |
| 7 | +--- |
| 8 | + |
| 9 | +Greetings from the Scala 3 team! We are glad to announce that Scala 3.0.1 and 3.0.2-RC1 are now officially out. |
| 10 | +As no critical bugs have been found in the previously released Scala 3.0.1-RC2, it has been promoted to 3.0.1, which is the first stable release after 3.0.0. Scala 3.0.2-RC1, in turn, incorporates new language improvements and bug fixes. |
| 11 | + |
| 12 | +<!--more--> |
| 13 | + |
| 14 | +# Improved insertion of semicolons in logical conditions |
| 15 | + |
| 16 | +Scala 3's indentation based syntax is aimed at making your code more concise and readable. As it gets broader adoption, we consistently improve its specification to eliminate corner cases which might lead to ambiguities or counterintuitive behaviours. |
| 17 | + |
| 18 | +Thanks to [#12801](https://github.com/lampepfl/dotty/pull/12801) it is now allowed for a logical expression in an `if` statement or expression to continue in the following line if it starts in the same line as the `if` keyword, e.g. |
| 19 | + |
| 20 | +```scala |
| 21 | +if foo |
| 22 | + (bar) |
| 23 | +then //... |
| 24 | +``` |
| 25 | + |
| 26 | +can now be used instead of |
| 27 | + |
| 28 | +```scala |
| 29 | +if foo(bar) |
| 30 | +then //... |
| 31 | +``` |
| 32 | + |
| 33 | +If yor intention is to have a block of code evaluating into a sigle condition you should add a new line and indentation directly after `if` , e.g. |
| 34 | + |
| 35 | +```scala |
| 36 | +if |
| 37 | + val cond = foo(bar) |
| 38 | + cond |
| 39 | +then //... |
| 40 | +``` |
| 41 | + |
| 42 | +so code like below would NOT be valid |
| 43 | + |
| 44 | +```scala |
| 45 | +if val cond = foo(bar) |
| 46 | + cond |
| 47 | +then //... |
| 48 | +``` |
| 49 | + |
| 50 | +# Method search by type signature |
| 51 | + |
| 52 | +You can now browse the documentation of Scala's API not only by names of methods but also by their type in a Hoogle-like manner thanks to integration with [Inkuire](https://github.com/VirtusLab/Inkuire) brought up by [#12375](https://github.com/lampepfl/dotty/pull/12375). |
| 53 | + |
| 54 | +To find a method with a specified signature simply write in scaladoc's searchbar the type you would expect it to have after eta-expansion (as if this was a function rather than a method). |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +# Typing escape hatch for structural types |
| 59 | + |
| 60 | +Structural types may come in handy in many situations, e.g. when one wants to achieve a compromise between safety of static typing and ease of use when dealing with dynamically changing schemas of domain data structures. They have however some limitations. Among others structural typing doesn't normally play well with method overloading because some types of reflective dispatch algorithms (inlcuding JVM reflection) might not be able to choose the overloaded method alternative with the right signature without knowing upfront the exact types of the parameters after erasure. Consider the following snippet. |
| 61 | + |
| 62 | +```scala |
| 63 | +class Sink[A] { def put(x: A): Unit = {} } |
| 64 | +val a = Sink[String]() |
| 65 | +val b: { def put(x: String): Unit } = a |
| 66 | +``` |
| 67 | + |
| 68 | +This code won't compile. This is because when `Sink[String]` gets erased to `Sink[Object]` (as it's seen from from JVM's perspective) the method's signature becomes `put(x: Object): Unit` while for the structural type it remains unchanged as `put(x: String): Unit` and they wouldn't match in runtime therefore `Sink[String]` cannot be treated as a subtype of `{ def put(x: String): Unit }`. |
| 69 | + |
| 70 | +We might however try to write a better method dispatch algorithm ourselves instead of relying on the JVM's default one to make this work. To assure the compiler that we know what we're doing we'll need to use the new `Selectable.WithoutPreciseParameterTypes` marker trait. Currently it's an experimental feature (introduced by [#12268](https://github.com/lampepfl/dotty/pull/12268)) so you'll be able to use it only with a snapshot or nightly version of the compiler and you'll need to annotate all subtypes of this trait with `@experimental`. |
| 71 | + |
| 72 | +```scala |
| 73 | +import annotation.experimental |
| 74 | + |
| 75 | +@experimental trait MultiMethodSelectable extends Selectable.WithoutPreciseParameterTypes: |
| 76 | + // smartly choose the right method implementation to call |
| 77 | + def applyDynamic(name: String, paramTypes: Class[_]*)(args: Any*): Any = ??? |
| 78 | + |
| 79 | +@experimental class Sink[A] extends MultiMethodSelectable: |
| 80 | + def put(x: A): Unit = {} |
| 81 | + |
| 82 | +val a = new Sink[String] |
| 83 | +val b: MultiMethodSelectable { def put(x: String): Unit } = a |
| 84 | +``` |
| 85 | + |
| 86 | +This snippet will compile as the compiler won't perform the precise signature check for `b` anymore. |
| 87 | + |
| 88 | +[More details](https://dotty.epfl.ch/docs/reference/changed-features/structural-types-spec.html#limitations-of-structural-types) |
| 89 | + |
| 90 | +# Metaprogramming |
| 91 | + |
| 92 | +Keeping in mind how important metaprogramming has become to Scala developers (especially creators of libraries) we continue to make it more reliable by fixing reported bugs and more powerful by repealing formerly introduced limitations. If you're curious how it was done investigate into the PRs below: |
| 93 | + |
| 94 | +- Map opaque types in arguments of inlined calls to proxies [#12922](https://github.com/lampepfl/dotty/pull/12922) |
| 95 | +- Don't forget side effects in prefixes of inlined function calls [#12842](https://github.com/lampepfl/dotty/pull/12842) |
| 96 | +- Drop "no inlines with opaques" implementation restriction [#12815](https://github.com/lampepfl/dotty/pull/12815) |
| 97 | +- Detect abstract inline method calls after inlining [#12777](https://github.com/lampepfl/dotty/pull/12777) |
| 98 | +- Fix implicit ValueOf synthesis [#12615](https://github.com/lampepfl/dotty/pull/12615) |
| 99 | + |
| 100 | +# Other notable improvements |
| 101 | + |
| 102 | +- Fix [#12981](https://github.com/lampepfl/dotty/issues/12981): show diagnostics levels (warn | error) in REPL [#13000](https://github.com/lampepfl/dotty/pull/13000) |
| 103 | +- Add no links warning setting to scaladoc [#12936](https://github.com/lampepfl/dotty/pull/12936) |
| 104 | +- Use WeakHashSet instead of HashSet for hash-consing types [#12935](https://github.com/lampepfl/dotty/pull/12935) |
| 105 | +- Balance And/Or types when forming lubs and glbs [#12928](https://github.com/lampepfl/dotty/pull/12928) |
| 106 | +- Restricts isInstanceOf[Null] checks [#12905](https://github.com/lampepfl/dotty/pull/12905) |
| 107 | +- Add support for shallow capture sets [#12875](https://github.com/lampepfl/dotty/pull/12875) |
| 108 | +- Drop implementation restriction for polymorphic functions [#12863](https://github.com/lampepfl/dotty/pull/12863) |
| 109 | +- Preserve hard unions in more situations [#12654](https://github.com/lampepfl/dotty/pull/12654) |
| 110 | +- Better support type-heavy pattern matches [#12549](https://github.com/lampepfl/dotty/pull/12549) |
| 111 | + |
| 112 | +# Other notable bug fixes |
| 113 | + |
| 114 | +- Fix [#13046](https://github.com/lampepfl/dotty/issues/13046): override is a valid identifier in Java, not a keyword [#13048](https://github.com/lampepfl/dotty/pull/13048) |
| 115 | +- Don't emit Java generic signatures for constructors [#13047](https://github.com/lampepfl/dotty/pull/13047) |
| 116 | +- Exhaustivity warnings on nested case classes [#13030](https://github.com/lampepfl/dotty/pull/13030) |
| 117 | +- Refine overriding pairs in RefChecks [#12982](https://github.com/lampepfl/dotty/pull/12982) |
| 118 | +- Let annotations on parameters see preceding type parameters [#12980](https://github.com/lampepfl/dotty/pull/12980) |
| 119 | +- Retain transparent flag on exports [#12978](https://github.com/lampepfl/dotty/pull/12978) |
| 120 | +- Widen unions before finding members [#12925](https://github.com/lampepfl/dotty/pull/12925) |
| 121 | +- ProtoTypes#normalizedCompatible: keep more constraints [#12924](https://github.com/lampepfl/dotty/pull/12924) |
| 122 | +- Detect provisional superclasses and recompute them in Typer [#12912](https://github.com/lampepfl/dotty/pull/12912) |
| 123 | +- Properly handle self-types in reflection member lookup [#12893](https://github.com/lampepfl/dotty/pull/12893) |
| 124 | +- Use Java rules for member lookup in .java sources [#12884](https://github.com/lampepfl/dotty/pull/12884) |
| 125 | +- Hide problematic static forwarders [#12860](https://github.com/lampepfl/dotty/pull/12860) |
| 126 | +- When checking tp1 <:< tycon2[args2], widen tp1 to reveal application [#12846](https://github.com/lampepfl/dotty/pull/12846) |
| 127 | +- Skip contexts for implicit search when resolving imports [#12816](https://github.com/lampepfl/dotty/pull/12816) |
| 128 | +- Insert conversions also on selections wrapped in type applications [#12719](https://github.com/lampepfl/dotty/pull/12719) |
| 129 | +- Emit generic signature for static forwarders to nullary methods [#12710](https://github.com/lampepfl/dotty/pull/12710) |
| 130 | +- Add Matchable to the parents of Null in explicit nulls [#12697](https://github.com/lampepfl/dotty/pull/12697) |
| 131 | +- Always generate a partial function from a lambda [#12670](https://github.com/lampepfl/dotty/pull/12670) |
| 132 | +- Fix [#12572](https://github.com/lampepfl/dotty/issues/12572): Ignore default accessor bridges in non-native JS classes. [#12657](https://github.com/lampepfl/dotty/pull/12657) |
| 133 | + |
| 134 | +# Contributors |
| 135 | +Thank you to all the contributors who made this release possible 🎉 |
| 136 | + |
| 137 | +According to `git shortlog -sn --no-merges 3.0.1-RC2..3.0.2-RC1` these are: |
| 138 | + |
| 139 | +``` |
| 140 | + 85 Martin Odersky |
| 141 | + 60 Liu Fengyun |
| 142 | + 47 Kacper Korban |
| 143 | + 28 Filip Zybała |
| 144 | + 17 Andrzej Ratajczak |
| 145 | + 16 Guillaume Martres |
| 146 | + 15 Jamie Thompson |
| 147 | + 10 bjornregnell |
| 148 | + 9 tanishiking |
| 149 | + 8 Dylan Halperin |
| 150 | + 8 Anatolii Kmetiuk |
| 151 | + 7 Tom Grigg |
| 152 | + 5 Som Snytt |
| 153 | + 5 changvvb |
| 154 | + 4 Nicolas Stucki |
| 155 | + 4 Aleksander Boruch-Gruszecki |
| 156 | + 4 Sébastien Doeraene |
| 157 | + 4 Michał Pałka |
| 158 | + 3 Magnolia.K |
| 159 | + 3 Phil |
| 160 | + 3 Krzysztof Romanowski |
| 161 | + 3 Paweł Marks |
| 162 | + 2 xuwei-k |
| 163 | + 2 Ben Plommer |
| 164 | + 2 Florian Schmaus |
| 165 | + 2 Lukas Rytz |
| 166 | + 2 Maciej Gorywoda |
| 167 | + 2 Markus Sutter |
| 168 | + 2 Roman Kotelnikov |
| 169 | + 2 Stéphane Micheloud |
| 170 | + 2 noti0na1 |
| 171 | + 2 vincenzobaz |
| 172 | + 1 Ondrej Lhotak |
| 173 | + 1 KazuyaMiayshita |
| 174 | + 1 odersky |
| 175 | + 1 Julian Mendez |
| 176 | + 1 Anton Sviridov |
| 177 | + 1 GavinRay97 |
| 178 | + 1 EnzeXing |
| 179 | + 1 Tomas Mikula |
| 180 | + 1 Tomasz Godzik |
| 181 | + 1 Vaastav Arora |
| 182 | + 1 Vadim Chelyshov |
| 183 | + 1 Will Sargent |
| 184 | + 1 Zofia Bartyzel |
| 185 | + 1 Dale Wijnand |
| 186 | + 1 Bjorn Regnell |
| 187 | + 1 dmitrii.naumenko |
| 188 | + 1 Adrien Piquerez |
| 189 | + 1 Meriam Lachkar |
| 190 | + 1 Martin |
| 191 | + 1 Olivier Blanvillain |
| 192 | + 1 Lorenzo Gabriele |
| 193 | +``` |
| 194 | + |
| 195 | +## Library authors: Join our community build |
| 196 | + |
| 197 | +Scala 3 now has a set of widely-used community libraries that are built against every nightly Scala 3 snapshot. |
| 198 | +Join our [community build](https://github.com/lampepfl/dotty/tree/master/community-build) |
| 199 | +to make sure that our regression suite includes your library. |
| 200 | + |
| 201 | +[Scastie]: https://scastie.scala-lang.org/?target=dotty |
| 202 | + |
| 203 | +[@odersky]: https://github.com/odersky |
| 204 | +[@DarkDimius]: https://github.com/DarkDimius |
| 205 | +[@smarter]: https://github.com/smarter |
| 206 | +[@felixmulder]: https://github.com/felixmulder |
| 207 | +[@nicolasstucki]: https://github.com/nicolasstucki |
| 208 | +[@liufengyun]: https://github.com/liufengyun |
| 209 | +[@OlivierBlanvillain]: https://github.com/OlivierBlanvillain |
| 210 | +[@biboudis]: https://github.com/biboudis |
| 211 | +[@allanrenucci]: https://github.com/allanrenucci |
| 212 | +[@Blaisorblade]: https://github.com/Blaisorblade |
| 213 | +[@Duhemm]: https://github.com/Duhemm |
| 214 | +[@AleksanderBG]: https://github.com/AleksanderBG |
| 215 | +[@milessabin]: https://github.com/milessabin |
| 216 | +[@anatoliykmetyuk]: https://github.com/anatoliykmetyuk |
0 commit comments