Skip to content
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

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

Open
OlgaDor opened this issue Jan 9, 2025 · 2 comments · May be fixed by #22435
Open

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

OlgaDor opened this issue Jan 9, 2025 · 2 comments · May be fixed by #22435
Assignees
Labels
area:parser itype:bug Spree Suitable for a future Spree

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 linked a pull request Jan 22, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:parser itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants