Skip to content

Commit 69750c8

Browse files
committed
Enable significant indentation after if.
There's one scenario where this breaks: ``` if (... ...) println() else if ... ``` This will be interpreted as ``` if { (... ...) println() } else if ... ``` and will fail with `then` expected at the point of the `else`. An example like this occurred in `SymDenotations.scala`.
1 parent 996820c commit 69750c8

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,11 +832,12 @@ object SymDenotations {
832832
| Access to protected $this not permitted because enclosing ${ctx.owner.enclosingClass.showLocated}
833833
| is not a subclass of ${owner.showLocated} where target is defined""")
834834
else if
835-
(!( isType // allow accesses to types from arbitrary subclasses fixes #4737
835+
!( isType // allow accesses to types from arbitrary subclasses fixes #4737
836836
|| pre.derivesFrom(cls)
837837
|| isConstructor
838838
|| owner.is(ModuleClass) // don't perform this check for static members
839-
))
839+
)
840+
then
840841
fail(
841842
i"""
842843
| Access to protected ${symbol.show} not permitted because prefix type ${pre.widen.show}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ object Tokens extends TokensCommon {
270270
final val closingRegionTokens = BitSet(RBRACE, CASE) | statCtdTokens
271271

272272
final val canStartIndentTokens: BitSet =
273-
statCtdTokens | BitSet(COLONEOL, EQUALS, ARROW, LARROW, WHILE, TRY, FOR, RETURN)
273+
statCtdTokens | BitSet(COLONEOL, EQUALS, ARROW, LARROW, WHILE, TRY, FOR, RETURN, IF)
274274
// `if` is excluded because it often comes after `else` which makes for awkward indentation rules TODO: try to do without the exception
275275

276276
/** Faced with the choice between a type and a formal parameter, the following

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ There are two rules:
2828
class, object, given, or enum definition, in an enum case, or after a package clause, or
2929
- after one of the following tokens:
3030
```
31-
= => <- then else while do try catch finally for yield match return
31+
= => <- if then else while do try catch finally for yield match return
3232
```
3333
If an `<indent>` is inserted, the indentation width of the token on the next line
3434
is pushed onto `IW`, which makes it the new current indentation width.

0 commit comments

Comments
 (0)