Skip to content

Commit

Permalink
No outdent at eof (#22435)
Browse files Browse the repository at this point in the history
Fixes #22332 

The reference does not mention `<eof>`. `<outdent>` insertion does not
require a particular next token, though some next tokens affect it (that
is, leading infix or tokens that close an indentation region). It does
require a "first token on the next line", for which we may take `<eof>`
as the lack of a token.

Of course, ordinary error messages say `eof`.

The same text with an opening brace is unchanged:
```
5 |
  | ^
  | '}' expected, but eof found
```
  • Loading branch information
som-snytt authored Jan 29, 2025
1 parent 5fe57c2 commit 81e057a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ object Scanners {
if nextWidth < lastWidth then currentRegion = topLevelRegion(nextWidth)
else if !isLeadingInfixOperator(nextWidth) && !statCtdTokens.contains(lastToken) && lastToken != INDENT then
currentRegion match
case _ if token == EOF => // no OUTDENT at EOF
case r: Indented =>
insert(OUTDENT, offset)
handleNewIndentWidth(r.enclosing, ir =>
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i22332.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

object Foo:
val foo = 42
// one space

0 comments on commit 81e057a

Please sign in to comment.