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
+33-1Lines changed: 33 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -243,6 +243,38 @@ case 5 => print("V")
243
243
println(".")
244
244
```
245
245
246
+
###UsingIndentation to SignalStatementContinuation
247
+
248
+
Indentation is used in some situations to decide whether to insert a virtual semicolon between
249
+
two consecutive lines or to treat them asone statement. Virtual semicolon insertion is
250
+
suppressed if the second line is indented more relative to the first one, and either the second line
251
+
starts with"`(`", "`[`", or "`{`" or the first line ends with`return`. Examples:
252
+
253
+
```scala
254
+
f(x +1)
255
+
(2, 3) // equivalent to `f(x + 1)(2, 3)`
256
+
257
+
g(x +1)
258
+
(2, 3) // equivalent to `g(x + 1); (2, 3)`
259
+
260
+
h(x +1)
261
+
{} // equivalent to `h(x + 1){}`
262
+
263
+
i(x +1)
264
+
{} // equivalent to `i(x + 1); {}`
265
+
266
+
if x <0thenreturn
267
+
a + b // equivalent to `if x < 0 then return a + b`
268
+
269
+
if x <0thenreturn
270
+
println(a + b) // equivalent to `if x < 0 then return; println(a + b)`
271
+
```
272
+
InScala2, a line starting with"`{`" always continues the function call on the preceding line,
273
+
irrespective of indentation, whereas a virtual semicolon is inserted in all other cases.
274
+
TheScala-2 behavior is retained under source `-no-indent` or `-source 3.0-migration`.
275
+
276
+
277
+
246
278
###TheEndMarker
247
279
248
280
Indentation-based syntax has many advantages over other conventions. But one possible problem is that it makes it hard to discern when a large indentation region ends, since there is no specific token that delineates the end. Braces are not much better since a brace by itself also contains no information about what region is closed.
@@ -404,7 +436,7 @@ end IndentWidth
404
436
405
437
###Settings and Rewrites
406
438
407
-
Significant indentation is enabled by default. It can be turned off by giving any of the options `-no-indent`, `-old-syntax` and `-language:Scala2`. If indentation is turned off, it is nevertheless checked that indentation conforms to the logical program structure asdefined by braces. If that is not the case, the compiler issues a warning.
439
+
Significant indentation is enabled by default. It can be turned off by giving any of the options `-no-indent`, `-old-syntax` and `-source 3.0-migration`. If indentation is turned off, it is nevertheless checked that indentation conforms to the logical program structure asdefined by braces. If that is not the case, the compiler issues a warning.
408
440
409
441
TheScala3 compiler can rewrite source code to indented code and back.
410
442
When invoked with options `-rewrite -indent` it will rewrite braces to
0 commit comments