Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare the 3.1.3 release blogpost #1393

Merged
merged 6 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions blog/_posts/2022-06-15-scala-3.1.3-released.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
layout: blog-detail
post-type: blog
by: Paweł Marks, VirtusLab
title: Scala 3.1.3 released!
---

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.
Kordyjan marked this conversation as resolved.
Show resolved Hide resolved

## Highlights of the release

Copy link
Member

@bishabosha bishabosha Jun 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scala/scala3#15275 - porting of scalac from bash to scala - will enable cs setup in future to match bash scalac command (when coursier/apps is patched to use the new class).

scala/scala3#15355 - windows batch files now match bash script launchers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is an essential change for most of our users. A lot of users are not aware of existence of launch scripts. Those who use them will also not see immediate improvements, as (if I remember correctly) this is just a new implementation with the same functionality.

The coursier part may be interesting, but it is still not implemented, so I wouldn't put that in the release notes.

### Improved f-interpolator

f-interpolator in Scala 3 has received multiple fixes and improvements recently. Now it has reached feature parity with its Scala 2 counterpart.

- Cases that were incorrectly failing are now working as intended:

```scala
f"${3.14}%.2f rounds to ${3}%d" // "3.14 rounds to 3"
f"${java.lang.Boolean.valueOf(false)}%b" // "false"
f"${BigInt(120)}%d" // "120"
f"${3L}%e" // "3.000000e+00"
```

- Backslash escapes are now handled properly and consistently:

```scala
f"yes\\\no" // "yes\
// o"
```

- Many cases that were throwing runtime exceptions are now causing compilation errors instead:

```scala
f"{1} % y" // Error: illegal conversion character 'y'
```

### Better error reporting in inlined code

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.

For example, the snippet:

```scala
trait Foo[X]:
def foo: Int

def foo =
first[String]

inline def second[A]: Int =
compiletime.summonInline[Foo[A]].foo

inline def first[A]: Int =
second[A] + 42
```

will now report compilation erro looking like this
Kordyjan marked this conversation as resolved.
Show resolved Hide resolved

![the new error]({{ site.baseurl }}/resources/img/inline-error-after.png)

instead of previous
Kordyjan marked this conversation as resolved.
Show resolved Hide resolved

![the old error]({{ site.baseurl }}/resources/img/inline-error-before.png)

### Possibility to generate arbitrary class implementations in macros

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:

```scala
import scala.quoted.*

class Base

transparent inline def classNamed(inline name: String) = new Base
Kordyjan marked this conversation as resolved.
Show resolved Hide resolved
def classNamedExpr(nameExpr: Expr[String])(using Quotes): Expr[Any] =
import quotes.reflect.*

val name = nameExpr.valueOrAbort
val parents = List(TypeTree.of[Base])
def decls(cls: Symbol) = List.empty // put something interesting here
val body = List.empty // ...and here

val symbol = Symbol.newClass(Symbol.spliceOwner, name, parents.map(_.tpe), decls, selfType = None)
val classDef = ClassDef(symbol, parents, body)
val ctor = Select(New(TypeIdent(symbol)), symbol.primaryConstructor)
val newClass = Typed(Apply(ctor, Nil), TypeTree.of[Base])

Block(List(classDef), newClass).asExprOf[Base]
```

Then you can invoke the macro with

```scala
val impl: Base = scope.classNamed("Foo")
Kordyjan marked this conversation as resolved.
Show resolved Hide resolved
```

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.

## Contributors

Thank you to all the contributors who made this release possible.

According to `git shortlog -sn --no-merges 3.1.2..3.1.3` these are:

```
// TODO
```
Binary file added resources/img/inline-error-after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/img/inline-error-before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.