JuliaSyntax.jl icon indicating copy to clipboard operation
JuliaSyntax.jl copied to clipboard

Begining blocks with colons

Open ParadaCarleton opened this issue 2 years ago • 0 comments

Python users moving to Julia often make a mistake like this:

julia> for i in randint(3):  # includes colon
           println(i)
    # no `end`
ERROR: ParseError:
# Error @ REPL[4]:1:21
#                   ┌
for i in randint(3):
    println(i)
#──┘ ── line break after `:` in range expression
# Error @ REPL[4]:2:15
for i in randint(3):
    println(i)
#             └ ── Expected `end`

Ideally, the error message should explain that colons aren't needed at the start of a block, and that end blocks are.

julia> for i in randint(3):  # includes colon
           println(i)
ERROR: ParseError:
# Error @ REPL[4]:1:21
#                   ┌
for i in randint(3):
    println(i)
#──┘ ── Colon (`:`) not needed to begin blocks
# Error @ REPL[4]:2:15
for i in randint(3):
    println(i)
#             └ ── `for` blocks must be closed with `end` keyword

ParadaCarleton avatar Sep 07 '23 16:09 ParadaCarleton