Skip to content

Commit a112f67

Browse files
committed
Update doc page
1 parent 421bdd6 commit a112f67

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

docs/_docs/reference/experimental/fewer-braces.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import language.experimental.fewerBraces
1212
```
1313
Alternatively, it can be enabled with command line option `-language:experimental.fewerBraces`.
1414

15-
This variant is more contentious and less stable than the rest of the significant indentation scheme. It allows to replace a function argument in braces by a `:` at the end of a line and indented code, similar to the convention for class bodies. It also allows to leave out braces around arguments that are multi-line function values.
15+
This variant is more contentious and less stable than the rest of the significant indentation scheme. It allows to replace a function argument in braces by a `:` at the end of a line and indented code, similar to the convention for class bodies. The `:` can
16+
optionally be followed by the parameter part of a function literal.
1617

1718
## Using `:` At End Of Line
1819

@@ -50,34 +51,31 @@ val firstLine = files.get(fileName).fold:
5051
5152
## Lambda Arguments Without Braces
5253
53-
Braces can also be omitted around multiple line function value arguments:
54+
The `:` can optionally be followed by the parameter part of a function literal:
5455
```scala
55-
val xs = elems.map x =>
56+
val xs = elems.map: x =>
5657
val y = x - 1
5758
y * y
5859
xs.foldLeft (x, y) =>
5960
x + y
6061
```
61-
Braces can be omitted if the lambda starts with a parameter list and `=>` or `=>?` at the end of one line and it has an indented body on the following lines.
62+
Braces can be omitted if the lambda starts with a parameter list and an arrow symbol `=>` or `?=>`.
63+
The arrow is followed on the next line(s) by the body of the functional literal which must be indented
64+
relative to the previous line.
6265
6366
## Syntax Changes
6467
68+
As a lexical change, a `:` at the end of a line is now always treated as a
69+
"colon at end of line" token.
70+
71+
The context free grammar changes as follows:
6572
```
6673
SimpleExpr ::= ...
67-
| SimpleExpr `:` IndentedArgument
68-
| SimpleExpr FunParams (‘=>’ | ‘?=>’) IndentedArgument
69-
InfixExpr ::= ...
70-
| InfixExpr id `:` IndentedArgument
71-
IndentedArgument ::= indent (CaseClauses | Block) outdent
72-
```
73-
74-
Note that a lambda argument must have the `=>` at the end of a line for braces
75-
to be optional. For instance, the following would also be incorrect:
74+
| SimpleExpr ‘:’ ColonArgument
7675

77-
```scala
78-
xs.map x => x + 1 // error: braces or parentheses are required
79-
```
80-
The lambda has to be enclosed in braces or parentheses:
81-
```scala
82-
xs.map(x => x + 1) // ok
76+
| SimpleExpr FunParams (‘=>’ | ‘?=>’) IndentedArgument
77+
ColonArgument ::= indent CaseClauses | Block outdent
78+
| FunParams (‘=>’ | ‘?=>’) ColonArgBody
79+
| HkTypeParamClause ‘=>’ ColonArgBody
80+
ColonArgBody ::= indent (CaseClauses | Block) outdent
8381
```

tests/pos/no-selftype.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import language.experimental.fewerBraces
2+
object f:
3+
def apply(x: Int) = println(x)
4+
5+
class C:
6+
f:
7+
22

0 commit comments

Comments
 (0)