Parser bug(?): syntax: extra token after end of expression

These two statements error, even though they seem unambiguous:

julia> begin
         () -> 3
       end()
ERROR: syntax: extra token "(" after end of expression
Stacktrace:
 [1] top-level scope
   @ none:1

julia> function()
         3
       end()
ERROR: syntax: extra token "(" after end of expression
Stacktrace:
 [1] top-level scope
   @ none:1

Adding extra parentheses fixes the issue:

julia> (begin
         () -> 3
       end)()
3

julia> (function()
         3
       end)()
3

The JuliaSyntax package has this same behavior as the built-in Julia parser.

3 Likes