Skip to content

Commit 0da59cd

Browse files
committed
Make indentation significant after ?=> and throw
1 parent 43d0b6c commit 0da59cd

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

compiler/src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ object Tokens extends TokensCommon {
276276
final val closingRegionTokens = BitSet(RBRACE, RPAREN, RBRACKET, CASE) | statCtdTokens
277277

278278
final val canStartIndentTokens: BitSet =
279-
statCtdTokens | BitSet(COLONEOL, WITH, EQUALS, ARROW, LARROW, WHILE, TRY, FOR, IF)
280-
// TODO: add THROW, CTXARROW
279+
statCtdTokens | BitSet(COLONEOL, WITH, EQUALS, ARROW, CTXARROW, LARROW, WHILE, TRY, FOR, IF, THROW)
281280

282281
/** Faced with the choice between a type and a formal parameter, the following
283282
* tokens determine it's a formal parameter.

docs/docs/reference/other-new-features/indentation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ There are two rules:
6464
- after one of the following tokens:
6565

6666
```
67-
= => <- catch do else finally for
68-
if match return then try while yield
67+
= => ?=> <- catch do else finally for
68+
if match return then throw try while yield
6969
```
7070

7171
If an `<indent>` is inserted, the indentation width of the token on the next line

tests/pos/indent.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ object Test:
5151
y * y
5252
}
5353

54+
val gg = (x: Int) ?=>
55+
val y = x + 1
56+
y
57+
5458
xs.map {
5559
x =>
5660
val y = x * x
@@ -80,11 +84,15 @@ object Test:
8084

8185
class Test2:
8286
self =>
83-
def foo = 1
87+
def foo(x: Int) =
88+
if x < 0 then throw
89+
val ex = new AssertionError()
90+
ex
91+
x
8492

8593
val x =
8694
new Test2 {
87-
override def foo = 2
95+
override def foo(x: Int) = 2
8896
}
8997
end x
9098
end Test2

0 commit comments

Comments
 (0)