Skip to content

Commit 6e84331

Browse files
committed
Tighten unary op syntax and untupling language
1 parent 1b70511 commit 6e84331

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

docs/_docs/reference/changed-features/operators.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ movedTo: https://docs.scala-lang.org/scala3/reference/changed-features/operators
66

77
The rules for infix operators have changed in some parts:
88

9-
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
10-
augment definitions of symbolic operators with [`@targetName` annotations](../other-new-features/targetName.md). Finally,
11-
a syntax change allows infix operators to be written on the left in a multi-line expression.
9+
First, an alphanumeric method can be used as an infix operator only if its definition carries an `infix` modifier.
10+
11+
Second, it is recommended (but not enforced) to augment definitions of symbolic operators
12+
with [`@targetName` annotations](../other-new-features/targetName.md).
13+
14+
Finally, a syntax change allows infix operators to be written on the left in a multi-line expression.
1215

1316
## The `infix` Modifier
1417

@@ -163,3 +166,10 @@ Another example:
163166

164167
This code is recognized as three different statements. `???` is syntactically a symbolic identifier, but
165168
neither of its occurrences is followed by a space and a token that can start an expression.
169+
170+
## Unary operators
171+
172+
As a minor restriction, the first parameter list of a unary operator must not be explicit and empty.
173+
A unary operator is a method named "unary_`op`" where `op` is one of `+`, `-`, `!`, or `~`.
174+
175+
The reason for this restriction is that unary operator syntax does not support supplying an argument list, even if it is empty.

docs/_docs/reference/other-new-features/parameter-untupling.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def combine(i: Int, j: Int) = i + j
3939
xs.map(combine)
4040
```
4141

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

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

0 commit comments

Comments
 (0)