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

Check trailing blank line at EOF for OUTDENT #22855

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Mar 21, 2025

Boost the previous fix for "spurious indentation error for blank line at EOF" by checking that the line is a non-empty blank line.

This accommodates REPL, which routinely parses lines at EOF.

Also improve the previous fix for "correctly detect colon arrow at EOL" by returning token EOF at EOF. The check for EOF when probing whether followingIsLambaAfterColon was specifically to accommodate REPL.

Fixes #22844

@som-snytt som-snytt force-pushed the issue/22844-repl-eol branch from ab9caa0 to 1d740e9 Compare March 21, 2025 17:56
@som-snytt
Copy link
Contributor Author

An adjustment is required.

scala> println:
     |   42
     |
42

scala> List(42).map: x =>
     |   x + 1
     |
val res0: List[Int] = List(43)

scala> List(42).map: x =>
-- Error: ----------------------------------------------------------------------
1 |List(42).map: x =>
  |^^^^^^^^^^^^^^^
  |not a legal formal parameter for a function literal

scala>

where res0 was from history, and the error shows "arrow eol" is still broken.

Also the scripted test does not actually pass.

In incomplete state, REPL re-parses on every character (IIUC); I expected to follow up with other improvements in that area.

@som-snytt som-snytt force-pushed the issue/22844-repl-eol branch from 1d740e9 to eb2c406 Compare March 22, 2025 10:04
@som-snytt
Copy link
Contributor Author

Dotty ReplTest does only single-line inputs; at least "scripted" test should work like Scala 2 SessionTest.

The gold standard integration test would run a REPL process from test input, in order to test incomplete input:

List(42).map: x =>// at eof
List(42).map: x =>\n// at eof
List(42).map: x =>\n  x+1// at eof
List(42).map: x =>\n  x+1\n\n // complete

The JLine parser could be tested for internal behavior, but scripted or "session" tests are easier to create and read.

@som-snytt som-snytt force-pushed the issue/22844-repl-eol branch from eb2c406 to 475b235 Compare March 22, 2025 11:41
@som-snytt som-snytt marked this pull request as ready for review March 22, 2025 16:19
@Gedochao Gedochao requested review from mbovel and hamzaremmal March 24, 2025 06:54
@Gedochao Gedochao added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

optional braces no longer work in repl
3 participants