Skip to content

a space on the last line of the file causes a compilation error #22332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OlgaDor opened this issue Jan 9, 2025 · 2 comments · Fixed by #22435
Closed

a space on the last line of the file causes a compilation error #22332

OlgaDor opened this issue Jan 9, 2025 · 2 comments · Fixed by #22435
Assignees
Milestone

Comments

@OlgaDor
Copy link

OlgaDor commented Jan 9, 2025

Compiler version

Scala compiler version 3.3.3 or later

Minimized code

object Foo:
  val foo = 1
 // one space on the last line of the file causes a compilation error

Output

[error] 3 | // one space on the last line of the file causes a compilation error
[error]   |                                                                     ^
[error]   |The start of this line does not match any of the previous indentation widths.
[error]   |Indentation width of current line : 1 space
[error]   |This falls between previous widths: 0 spaces and 2 spaces
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

The compilation error results in red code in IntelliJ IDEA

Expectation

The code should compile without errors

@OlgaDor OlgaDor added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 9, 2025
@som-snytt
Copy link
Contributor

Specifically, a last line consisting of a space with no terminal newline.

vim refresher

vim -b last-space.scala
:set noeol
:wq
5 |
  | ^
  |The start of this line does not match any of the previous indentation widths.
  |Indentation width of current line : 1 space
  |This falls between previous widths: 0 spaces and 2 spaces
1 error found
Compilation failed

where

➜  hexdump -C last-space.scala
00000000  0a 6f 62 6a 65 63 74 20  46 6f 6f 3a 0a 20 20 76  |.object Foo:.  v|
00000010  61 6c 20 66 6f 6f 20 3d  20 34 32 0a 20 2f 2f 20  |al foo = 42. // |
00000020  6f 6e 65 20 73 70 61 63  65 0a 20                 |one space. |
0000002b

@unkarjedy
Copy link
Contributor

This can be important when copy/pasting code examples
Also, during editing the code, e.g. in IntelliJ when you have compiler-based highlighting, the file tab can "randomly" become red indicating a compilation error.
Probably the same would be in Metals, haven't checked

@KacperFKorban KacperFKorban self-assigned this Jan 10, 2025
@KacperFKorban KacperFKorban added area:parser and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 10, 2025
@mbovel mbovel added the Spree Suitable for a future Spree label Jan 13, 2025
@som-snytt som-snytt removed the Spree Suitable for a future Spree label Jan 27, 2025
KacperFKorban pushed a commit that referenced this issue Jan 29, 2025
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
```
@WojciechMazur WojciechMazur added this to the 3.7.0 milestone Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants