Skip to content

Commit 808c669

Browse files
Merge pull request #14372 from som-snytt/issue/9241
Tighten unary op syntax and untupling language
2 parents 58171fb + 60f85f4 commit 808c669

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

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

Lines changed: 11 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,8 @@ 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+
A unary operator must not have explicit parameter lists even if they are empty.
173+
A unary operator is a method named "unary_`op`" where `op` is one of `+`, `-`, `!`, or `~`.

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)