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

Note changes in unicode escapes and case companion #2943

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions _overviews/FAQ/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ REPL, but won't work in typical Scala 3 application code.
For an alternative way to detect the Scala 3 version, see
[this gist](https://gist.github.com/romanowski/de14691cab7340134e197419bc48919a).

### I want to use Scala 3 but now a bunch of stuff just broke in my project. What's up with that?
Copy link
Member

Choose a reason for hiding this comment

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

I do not think this should be in the FAQ.


There is a [guide for migration](https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html)
that includes a [table of incompatibilities](https://docs.scala-lang.org/scala3/guides/migration/incompatibility-table.html).
Incompatibilities are largely due to dropping old features and introducing new ones,
rather than subtle changes in existing features.
The migration guide provides strategies for either migrating to new syntax or maintaining cross-compatibility.

### Why is my (abstract or overridden) `val` null?

<!-- this is left over from a previous version of the FAQ.
Expand Down
29 changes: 28 additions & 1 deletion _overviews/scala3-migration/incompat-other-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,33 @@ fooCtr.tupled((2, false))
~~~
{% endtab %}
{% endtabs %}

To assist migration, the compiler will insert the call to `apply` as needed:
{% tabs scala-3-companion_3 %}
{% tab 'Scala 3 Only' %}
~~~ scala
case class C(i: Int)
List(42).map(C)
case class D(i: Int, j: Int)
List(42->27).map(D)
~~~
{% endtab %}
{% endtabs %}

In Scala 2.13.13, this behavior is enabled under `-Xsource:3cross`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In Scala 2.13.13, this behavior is enabled under `-Xsource:3cross`.
In Scala 2.13.13, this behavior is enabled under `-Xsource:3-cross`.

That is, case companions that do not extend `Function` can be used as if they did,
or equivalently, as though `apply` were inserted. However, since Scala 2 does not
adapt `apply` for the tupled case, `tupled` is supported directly.
{% tabs scala-3-companion_4 %}
{% tab 'Scala 2 Only' %}
~~~ scala
case class C(i: Int); object C
List(42).map(C)
case class D(i: Int, j: Int); object D
List(42->27).map(D.tupled)
~~~
{% endtab %}
{% endtabs %}
## Explicit Call to `unapply`

In Scala, case classes have an auto-generated extractor method, called `unapply` in their companion object.
Expand Down Expand Up @@ -325,4 +352,4 @@ In such case, we can use a wrapper class around `Foo`:

-def g(foos: Seq[Foo[_]]): Unit
+def g(foos: Seq[FooWrapper[_]]): Unit
{% endhighlight %}
{% endhighlight %}
11 changes: 11 additions & 0 deletions _overviews/scala3-migration/incompat-syntactic.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ It is worth noting that most of the changes can be automatically handled during
|[Wrong indentation](#wrong-indentation)||||
|[`_` as a type parameter](#_-as-a-type-parameter)||||
|[`+` and `-` as type parameters](#-and---as-type-parameters)||||
|[Unicode escapes](incompat-syntactic.html#unicode-escapes)||||

## Restricted Keywords

Expand Down Expand Up @@ -237,3 +238,13 @@ The solution is to choose another valid identifier, for instance `T`.

However, `+` and `-` still are valid type identifiers in general.
You can write `type +`.

## Unicode escapes

Unicode escapes of the form `\u0061` are no longer natively supported in any position by the compiler.
Copy link
Member

Choose a reason for hiding this comment

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

"natively supported" seems unclear to me. not sure what best replacement is, maybe:

Suggested change
Unicode escapes of the form `\u0061` are no longer natively supported in any position by the compiler.
Unicode escapes of the form `\u0061` are no longer allowed in arbitrary locations in source code.


Instead, they processed like other escapes in string literals.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Instead, they processed like other escapes in string literals.
Instead, they are processed in string literals, just like other escape sequences.

This means, in particular, that they are not processed in "triple-quoted" strings or by the `raw` interpolator.

In Scala 2, a deprecation is issued, but under `-Xsource:3cross`, the behavior is the same as Scala 3.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In Scala 2, a deprecation is issued, but under `-Xsource:3cross`, the behavior is the same as Scala 3.
In Scala 2, a deprecation is issued, but under `-Xsource:3-cross`, the behavior is the same as Scala 3.


1 change: 1 addition & 0 deletions _overviews/scala3-migration/incompatibility-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Some of the old syntax is not supported anymore.
|[Wrong indentation](incompat-syntactic.html#wrong-indentation)||||
|[`_` as a type parameter](incompat-syntactic.html#_-as-a-type-parameter)||||
|[`+` and `-` as type parameters](incompat-syntactic.html#-and---as-type-parameters)||||
|[Unicode escapes](incompat-syntactic.html#unicode-escapes)||||

### Dropped Features

Expand Down
Loading