Skip to content

Tighten unary op syntax and untupling language #14372

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

Merged
merged 2 commits into from
Mar 8, 2022
Merged
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
14 changes: 11 additions & 3 deletions docs/_docs/reference/changed-features/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ movedTo: https://docs.scala-lang.org/scala3/reference/changed-features/operators

The rules for infix operators have changed in some parts:

First, an alphanumeric method can be used as an infix operator only if its definition carries an `infix` modifier. Second, it is recommended (but not enforced) to
augment definitions of symbolic operators with [`@targetName` annotations](../other-new-features/targetName.md). Finally,
a syntax change allows infix operators to be written on the left in a multi-line expression.
First, an alphanumeric method can be used as an infix operator only if its definition carries an `infix` modifier.

Second, it is recommended (but not enforced) to augment definitions of symbolic operators
with [`@targetName` annotations](../other-new-features/targetName.md).

Finally, a syntax change allows infix operators to be written on the left in a multi-line expression.

## The `infix` Modifier

Expand Down Expand Up @@ -163,3 +166,8 @@ Another example:

This code is recognized as three different statements. `???` is syntactically a symbolic identifier, but
neither of its occurrences is followed by a space and a token that can start an expression.

## Unary operators

A unary operator must not have explicit parameter lists even if they are empty.
A unary operator is a method named "unary_`op`" where `op` is one of `+`, `-`, `!`, or `~`.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def combine(i: Int, j: Int) = i + j
xs.map(combine)
```

Generally, a function value with `n > 1` parameters is converted to a
pattern-matching closure using `case` if the expected type is a unary
function type of the form `((T_1, ..., T_n)) => U`.
Generally, a function value with `n > 1` parameters is wrapped in a
function type of the form `((T_1, ..., T_n)) => U` if that is the expected type.
The tuple parameter is decomposed and its elements are passed directly to the underlying function.

More specifically, the adaptation is applied to the mismatching formal
parameter list. In particular, the adaptation is not a conversion
Expand Down