Skip to content

Commit 9e05dba

Browse files
som-snytttgodzik
authored andcommitted
No outdent at eof (scala#22435)
Fixes scala#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 ``` [Cherry-picked 81e057a]
1 parent 68e6ec2 commit 9e05dba

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ object Scanners {
615615
if nextWidth < lastWidth then currentRegion = topLevelRegion(nextWidth)
616616
else if !isLeadingInfixOperator(nextWidth) && !statCtdTokens.contains(lastToken) && lastToken != INDENT then
617617
currentRegion match
618+
case _ if token == EOF => // no OUTDENT at EOF
618619
case r: Indented =>
619620
insert(OUTDENT, offset)
620621
handleNewIndentWidth(r.enclosing, ir =>

tests/pos/i22332.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
object Foo:
3+
val foo = 42
4+
// one space
5+

0 commit comments

Comments
 (0)