-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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. | ||||||
|
@@ -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 %} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
|
||||||
|
@@ -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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
|
||||||
Instead, they processed like other escapes in string literals. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
There was a problem hiding this comment.
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.