Commit 6609022
committed
Better handling of leading infix operators in indented code
```code
@main def Test =
val x = false
val y = 1
val result =
x
|| y.match
case 1 => false
case 3 => false
case _ => true
|| !x
assert(result)
```
In this code, the last `|| !x` was seen as a part of the previous case, so the code was parsed as
```scala
@main def Test =
val x = false
val y = 1
val result =
x
|| y.match
case 1 => false
case 3 => false
case _ => true || !x
assert(result)
```
This is highly surprising and unintuitive. The fix will insert an <outdent> token instead
if the leading infix operator is too far to the left. Too far means: (1) left of the current indentation
region, (2) and not to the right of any outer indentation widths.
(2) allows to still parse code like this
```scala
if xyz then
one
+ two
+ three
```
Here, the width of the indentation region after `then` is 4, but the `+` operator is to the right
of the outer indentation width of 0., so the indentation region is not closed. In other words,
we do not close an indentation region if the result would not be legal, since it matches none of
the previous indentation widths.1 parent f01c14d commit 6609022
File tree
3 files changed
+52
-5
lines changed- compiler/src/dotty/tools/dotc/parsing
- docs/docs/reference/other-new-features
- tests/run
3 files changed
+52
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | | - | |
| 372 | + | |
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| |||
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
400 | 414 | | |
401 | 415 | | |
402 | 416 | | |
| |||
512 | 526 | | |
513 | 527 | | |
514 | 528 | | |
515 | | - | |
| 529 | + | |
516 | 530 | | |
517 | 531 | | |
518 | 532 | | |
| |||
521 | 535 | | |
522 | 536 | | |
523 | 537 | | |
524 | | - | |
| 538 | + | |
525 | 539 | | |
526 | 540 | | |
527 | 541 | | |
| |||
1105 | 1119 | | |
1106 | 1120 | | |
1107 | 1121 | | |
1108 | | - | |
| 1122 | + | |
1109 | 1123 | | |
1110 | 1124 | | |
1111 | 1125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
| |||
105 | 108 | | |
106 | 109 | | |
107 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
108 | 129 | | |
109 | 130 | | |
110 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments