From 9e05dba93785bedcfc3b43c5aae0e7c6412a34ab Mon Sep 17 00:00:00 2001 From: som-snytt Date: Wed, 29 Jan 2025 02:45:59 -0800 Subject: [PATCH] No outdent at eof (#22435) Fixes #22332 The reference does not mention ``. `` 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 `` 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 81e057a8d4bcde2d8cee628b8b02f90fbfb05954] --- compiler/src/dotty/tools/dotc/parsing/Scanners.scala | 1 + tests/pos/i22332.scala | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 tests/pos/i22332.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index aadedde612f7..57a7ff1c4a9b 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -615,6 +615,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 => diff --git a/tests/pos/i22332.scala b/tests/pos/i22332.scala new file mode 100644 index 000000000000..1b0b6a370329 --- /dev/null +++ b/tests/pos/i22332.scala @@ -0,0 +1,5 @@ + +object Foo: + val foo = 42 + // one space + \ No newline at end of file