Skip to content

Commit cacfdb0

Browse files
committed
Prepare the 3.1.3 release blogpost
1 parent 585f93a commit cacfdb0

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
layout: blog-detail
3+
post-type: blog
4+
by: Paweł Marks, VirtusLab
5+
title: Scala 3.1.3 released!
6+
---
7+
8+
We are happy to announce the release of Scala 3.1.3! You can read more about all the improvements and fixes in [the full changelog](https://github.com/lampepfl/dotty/releases/tag/3.1.3). We have also prepared a short highlights of the most exciting additions in the new version.
9+
10+
## Highlights of the release
11+
12+
### Improved f-interpolator
13+
14+
f-interpolator in Scala 3 has received multiple fixes and improvements recently. Now it has reached feature parity with its Scala 2 counterpart.
15+
16+
- Cases that were incorrectly failing are now working as intended:
17+
18+
```scala
19+
f"${3.14}%.2f rounds to ${3}%d" // "3.14 rounds to 3"
20+
f"${java.lang.Boolean.valueOf(false)}%b" // "false"
21+
f"${BigInt(120)}%d" // "120"
22+
f"${3L}%e" // "3.000000e+00"
23+
```
24+
25+
- Backslash escapes are now handled properly and consistently:
26+
27+
```scala
28+
f"yes\\\no" // "yes\
29+
// o"
30+
```
31+
32+
- Many cases that were throwing runtime exceptions are now causing compilation errors instead:
33+
34+
```scala
35+
f"{1} % y" // Error: illegal conversion character 'y'
36+
```
37+
38+
### Better error reporting in inlined code
39+
40+
When the compiler reports an error that occurred in inlined code, it now displays the source from where the inlined function was invoked. That gives more context to the users on what happened and where the error came from.
41+
42+
For example, the snippet:
43+
44+
```scala
45+
trait Foo[X]:
46+
def foo: Int
47+
48+
def foo =
49+
first[String]
50+
51+
inline def second[A]: Int =
52+
compiletime.summonInline[Foo[A]].foo
53+
54+
inline def first[A]: Int =
55+
second[A] + 42
56+
```
57+
58+
will now report compilation erro looking like this
59+
60+
![the new error]({{ site.baseurl }}/resources/img/inline-error-after.png)
61+
62+
instead of previous
63+
64+
![the old error]({{ site.baseurl }}/resources/img/inline-error-before.png)
65+
66+
### Possibility to generate arbitrary class implementations in macros
67+
68+
For a long time, generating arbitrary classes was not possible using the quotes api. With 3.1.3, the situation has changed. We added two missing blocks: experimental methods `ClassDef.apply` and `Symbol.newClass`. Now using them, you can write a snippet similar to the following:
69+
70+
```scala
71+
import scala.quoted.*
72+
73+
class Base
74+
75+
transparent inline def classNamed(inline name: String) = new Base
76+
def classNamedExpr(nameExpr: Expr[String])(using Quotes): Expr[Any] =
77+
import quotes.reflect.*
78+
79+
val name = nameExpr.valueOrAbort
80+
val parents = List(TypeTree.of[Base])
81+
def decls(cls: Symbol) = List.empty // put something interesting here
82+
val body = List.empty // ...and here
83+
84+
val symbol = Symbol.newClass(Symbol.spliceOwner, name, parents.map(_.tpe), decls, selfType = None)
85+
val classDef = ClassDef(symbol, parents, body)
86+
val ctor = Select(New(TypeIdent(symbol)), symbol.primaryConstructor)
87+
val newClass = Typed(Apply(ctor, Nil), TypeTree.of[Base])
88+
89+
Block(List(classDef), newClass).asExprOf[Base]
90+
```
91+
92+
Then you can invoke the macro with
93+
94+
```scala
95+
val impl: Base = scope.classNamed("Foo")
96+
```
97+
98+
creating the new instance of your custom subclass of `Base`. That can be useful for the compile-time generation of proxies for remote procedure call systems and many other advanced use-cases.
99+
100+
## Contributors
101+
102+
Thank you to all the contributors who made this release possible.
103+
104+
According to `git shortlog -sn --no-merges 3.1.2..3.1.3` these are:
105+
106+
```
107+
// TODO
108+
```

resources/img/inline-error-after.png

66 KB
Loading

resources/img/inline-error-before.png

40.3 KB
Loading

0 commit comments

Comments
 (0)