You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The fixes omit documenting `:` in extension blocks. These will be disabled
in a separate commit.
There are two reasons for omitted in `:` in extensions:
- they are not needed, and there should be one way to do things
- they are confusing since everywhere else a `:` at eol starts a
new scope, but here it doesn't.
Copy file name to clipboardExpand all lines: docs/docs/reference/other-new-features/indentation.md
+9-17Lines changed: 9 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -58,8 +58,8 @@ There are two rules:
58
58
59
59
An indentation region can start
60
60
61
-
- after the condition of an `if-else`, or
62
61
- after the leading parameters of an `extension`, or
62
+
- after a `with` in a giveninstance, or
63
63
- after a ": at end of line" token (see below)
64
64
- after one of the following tokens:
65
65
@@ -93,7 +93,7 @@ There are two rules:
93
93
It is an error if the indentation width of the token following an `<outdent>` does not match the indentation of some previous line in the enclosing indentation region. For instance, the following would be rejected.
94
94
95
95
```scala
96
-
if x <0
96
+
if x <0then
97
97
-x
98
98
else// error: `else` does not align correctly
99
99
x
@@ -104,14 +104,14 @@ at the toplevel, inside braces `{...}`, but not inside parentheses `(...)`, patt
104
104
105
105
###OptionalBracesAroundTemplateBodies
106
106
107
-
TheScala grammar uses the term _template body_ for the definitions of a class, trait, objectorgiveninstance that are normally enclosed in braces. The braces around a template body can also be omitted by means of the following rule
107
+
TheScala grammar uses the term _template body_ for the definitions of a class, trait, or objectthat are normally enclosed in braces. The braces around a template body can also be omitted by means of the following rule
108
108
109
109
If at the point where a template body can start there is a `:` that occurs at the end
110
110
of a line, and that is followed by at least one indented statement, the recognized
111
111
token is changed from ":" to ": at end of line". The latter token is one of the tokens
112
112
that can start an indentation region. TheScala grammar is changed so an optional ": at end of line" is allowed in front of a template body.
113
113
114
-
Analogous rules apply forenumbodies, typerefinements, definitions in an instance creation expressions, and local packages containing nested definitions.
114
+
Analogous rules apply forenumbodies and local packages containing nested definitions.
115
115
116
116
With these new rules, the following constructs are all valid:
117
117
@@ -128,15 +128,6 @@ object O:
128
128
enumColor:
129
129
caseRed, Green, Blue
130
130
131
-
typeT=A:
132
-
deff:Int
133
-
134
-
given [T](usingOrd[T]):Ord[List[T]] with
135
-
defcompare(x: List[T], y: List[T]) =???
136
-
137
-
extension (xs: List[Int])
138
-
defsecond:Int= xs.tail.head
139
-
140
131
newA:
141
132
deff=3
142
133
@@ -145,14 +136,15 @@ package p:
145
136
packageq:
146
137
defb=2
147
138
```
139
+
In each case, the `:` at the end of line can be replaced without change of meaning by a pair of braces that enclose the following indented definition(s).
0 commit comments