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

Error when trying :load file in REPL (scala) - "unindent expected, but eof found" #15808

Closed
calculusbearmudriyjo opened this issue Aug 2, 2022 · 1 comment · Fixed by #15811
Assignees
Milestone

Comments

@calculusbearmudriyjo
Copy link

calculusbearmudriyjo commented Aug 2, 2022

I try load file in scala REPL (scala console tool)
by command

:load src/main/scala/Main.scala

and have error with loading (see below)

Compiler version

Scala version 3.1.3 and reproduce on 3.1.2

Minimized code

@main def hello: Unit = 
  fizzBuzz


def fizzBuzz: Unit = 
  for
    i <- 1 to 100
  do
    val x = if i % 5 == 0 then "Fizz"
      else if i % 3 == 0 then "Buzz"
      else if i % 5 == 0 && i % 3 == 0 then "FizzBuzz"
      else i
    println(x)

Output

-- [E040] Syntax Error: --------------------------------------------------------
13 |    println(x)
   |              ^
   |              unindent expected, but eof found

Expectation

load module to repl without error

@calculusbearmudriyjo calculusbearmudriyjo added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 2, 2022
@som-snytt
Copy link
Contributor

som-snytt commented Aug 2, 2022

I had to strip the final newline to reproduce:

scala> val p = java.nio.file.Path.of("truncated.scala")
val p: java.nio.file.Path = truncated.scala

scala> val src = io.Source.fromFile("file.scala")
val src: scala.io.BufferedSource = <iterator>

scala> java.nio.file.Files.writeString(p, src.toArray.init.mkString)
val res0: java.nio.file.Path = truncated.scala

scala> :load truncated.scala
-- [E040] Syntax Error: ------------------------------------------------------------------------------------------------
14 |    println(x)
   |              ^
   |              unindent expected, but eof found

scala> :load file.scala
def hello: Unit
def fizzBuzz: Unit

scala>

I think I saw a PR related to EOF? [I was thinking of a different parser issue.]

Edit: first I tried the file with CR-LF, so actually my test had a trailing CR, which is why the error was on "line 15".

Usually, when people say "significant whitespace", they mean leading and not trailing.

@som-snytt som-snytt self-assigned this Aug 3, 2022
@som-snytt som-snytt removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Aug 3, 2022
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 2, 2023
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.

4 participants