Let x = 1 # ParseError

I don’t know what’s going wrong here.

PS K:\uc24> julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.5 (2025-04-14)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |
julia> let x = 1
       x
       end
1

julia> let x = 1 #
ERROR: ParseError:
# Error @ REPL[2]:1:10
let x = 1 #
#        └ ── premature end of input
Stacktrace:
 [1] top-level scope
   @ none:1
1 Like

It looks like that functions don’t suffer this

julia> function mysum(a, #
       b)
       return a + b
       end
mysum (generic function with 1 method)

julia> mysum(3, 4)
7

Might be an issue with the REPL and how unfinished expressions are recognized? Or perhaps there is some ambiguity in the unfinished let block?

The function example should work because the open parenthesis ( is always enough to tell that the expression is not complete yet.

But this also works

julia> begin x = 1 #
       end
1

Definitely a REPL limitation, like how we get a ParseError in strings or code if we input too many newlines even though that’d be fine if include-d from a file. Couple weird workarounds:

julia> let x = 1 # wrote this comment after the next line
        x
       end
1

julia> let x = 1; # wrote this comment immediately
        x
       end
1
1 Like

So it’s a bug. Will it be fixed?


Update: I’ve opened an issue Let x = 1 # ParseError · Issue #58782 · JuliaLang/julia · GitHub

1 Like

Like most users, I have no idea. You might see where the developers are at if you open a Github issue about this. If it’ll help, this particular REPL limitation seems to have started in v1.10 when JuliaSyntax.jl replaced the femtolisp-based parser; you can confirm by comparing v1.9 and v1.10.

2 Likes