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
Copy file name to clipboardExpand all lines: docs/docs/reference/other-new-features/indentation.md
+13-7Lines changed: 13 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -198,15 +198,21 @@ def largeMethod(...) =
198
198
... // more code
199
199
endlargeMethod
200
200
```
201
-
An `end` marker consists of the identifier `end` which follows an `<outdent>` token, and is in turn followed on the same line by exactly one other token, which is either an identifier or one of the reserved words
201
+
An `end` marker consists of the identifier `end` and a follow-on specifier token that together constitute all the tokes of a line. Possible specifier tokens are
202
+
identifiers or one of the following keywords
202
203
```scala
203
-
ifwhileformatchtrynewgivenextension
204
+
ifwhileformatchtrynewthisvalgiven
204
205
```
205
-
If `end` is followed by a reserved word, the compiler checks that the marker closes an indentation region belonging to a construct that starts with the reserved word. If it is followed by an identifier _id_, the compiler checks that the marker closes a definition
206
-
that defines _id_ or a packageclausethatrefersto_id_.
207
-
208
-
`end` itself is a soft keyword. It is only treated asan `end` marker if it
209
-
occurs at the start of a line and is followed by an identifier or one of the reserved words above.
206
+
End markers are allowed in statement sequences. The specifier token `s` of an end marker must correspond to the statement that precedes it. Thismeans:
207
+
208
+
-If the statement defines a member `x` then `s` must be the same identifier `x`.
209
+
-If the statement defines a constructor then `s` must be `this`.
210
+
-If the statement defines an anonymous given, then `s` must be `given`.
211
+
-If the statement defines an anonymous extension, then `s` must be `extension`.
212
+
-If the statement defines an anonymous class, then `s` must be `new`.
213
+
-If the statement is a `val` definition binding a pattern, then `s` must be `val`.
214
+
-If the statement is a packageclausethatreferstopackage`p`, then`s`mustbethesameidentifier`p`.
215
+
-If the statement is an `if`, `while`, `for`, `try`, or `match` statement, then `s` must be that same token.
210
216
211
217
It is recommended that `end` markers are used for code where the extent of an indentation region is not immediately apparent "at a glance". Typicallythis is the caseif an indentation region spans 20 lines or more.
0 commit comments