JuliaLang / JuliaSyntax.jl

The Julia compiler frontend
Other
274 stars 33 forks source link

"JuliaSyntax parser failed — falling back to flisp!" for unexpected character in `do` block #340

Closed topolarity closed 1 year ago

topolarity commented 1 year ago

Parsing this malformed code:

foo() do x
    ]
end

triggers this unhelpful error + huge backtrace from JuliaSyntax:

┌ Error: JuliaSyntax parser failed — falling back to flisp!
│   exception =
│    Internal error: length(args) == 3
│    Stacktrace:
│      [1] error(::String, ::String)
│        @ Base ./error.jl:44
│      [2] internal_error(strs::String)
│        @ Base.JuliaSyntax /build/julia/base/JuliaSyntax/src/utils.jl:23
│      [3] _internal_node_to_Expr(source::Base.JuliaSyntax.SourceFile, srcrange::UnitRange{…}, head::Base.JuliaSyntax.SyntaxHead, childranges::Vector{…}, childheads::Vector{…}, args::Vector{…})
│        @ Base.JuliaSyntax /build/julia/base/JuliaSyntax/src/expr.jl:399
│      [4] _to_expr(node::Base.JuliaSyntax.SyntaxNode)
│        @ Base.JuliaSyntax /build/julia/base/JuliaSyntax/src/expr.jl:497
│      [5] _to_expr(node::Base.JuliaSyntax.SyntaxNode)
│        @ Base.JuliaSyntax /build/julia/base/JuliaSyntax/src/expr.jl:496
│      [6] Expr(node::Base.JuliaSyntax.SyntaxNode)
│        @ Base.JuliaSyntax /build/julia/base/JuliaSyntax/src/expr.jl:501
│      [7] core_parser_hook(code::String, filename::String, lineno::Int64, offset::Int64, options::Symbol)
│        @ Base.JuliaSyntax /build/julia/base/JuliaSyntax/src/hooks.jl:209
│      [8] invoke_in_world(::UInt64, ::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
│        @ Base ./essentials.jl:898
│      [9] invoke_in_world(::UInt64, ::Any, ::Any, ::Vararg{Any})
│        @ Base ./essentials.jl:895
│     [10] (::Base.JuliaSyntax.var"#invoke_fixedworld#119"{…})(::String, ::Vararg{…}; kws::@Kwargs{})
│        @ Base.JuliaSyntax /build/julia/base/JuliaSyntax/src/hooks.jl:118
│     [11] (::Base.JuliaSyntax.var"#invoke_fixedworld#119"{Base.JuliaSyntax.var"#invoke_fixedworld#116#120"{…}})(::String, ::Vararg{Any})
│        @ Base.JuliaSyntax /build/julia/base/JuliaSyntax/src/hooks.jl:117
│     [12] _parse_string(text::String, filename::String, lineno::Int64, index::Int64, options::Symbol)
│        @ Base.Meta ./meta.jl:200
│     [13] parseall(text::String; filename::String, lineno::Int64)
│        @ Base.Meta ./meta.jl:292 [inlined]
│     [14] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
│        @ Base ./loading.jl:1997
│     [15] _include(mapexpr::Function, mod::Module, _path::String)
│        @ Base ./loading.jl:2071
│     [16] include(mod::Module, _path::String)
│        @ Base ./Base.jl:489
│     [17] exec_options(opts::Base.JLOptions)
│        @ Base ./client.jl:318
│     [18] _start()
│        @ Base ./client.jl:552
│    Some type information was truncated. Use `show(err)` to see complete types.
│   offset = 0
│   code = "foo() do x\n    ]\nend\n"
└ @ Base.JuliaSyntax /build/julia/base/JuliaSyntax/src/hooks.jl:258
topolarity commented 1 year ago

It would be very nice in general not to print the long backtrace here.

Instead, I think it'd be better to provide instructions for reporting this bug upstream.

vchuravy commented 1 year ago

Maybe we can turn that from @error to @debug? With an @error to "report issue upstream"

LilithHafner commented 1 year ago

I view this type of error similarly to an unexpected internal error in the Julia runtime—we need to avoid them entirely, not make them pretty, though I also think this error message should be more clear that it should be reported upstream.

gaurav-arya commented 1 year ago

Just hit a similar case (on 1.10.0-beta2):

julia> map([3,4,5])[1] do
┌ Error: JuliaSyntax parser failed — falling back to flisp!
│   exception =
│    Internal error: length(args) == 3
│    Stacktrace:
│      [1] error(::String, ::String)
│        @ Base ./error.jl:44
│      [2] internal_error(strs::String)
│        @ Base.JuliaSyntax /cache/build/default-amdci5-3/julialang/julia-release-1-dot-10/base/JuliaSyntax/src/utils.jl:23
│      [3] _internal_node_to_Expr(source::Base.JuliaSyntax.SourceFile, srcrange::UnitRange{…}, head::Base.JuliaSyntax.SyntaxHead, childranges::Vector{…}, childheads::Vector{…}, args::Vector{…})
│        @ Base.JuliaSyntax /cache/build/default-amdci5-3/julialang/julia-release-1-dot-10/base/JuliaSyntax/src/expr.jl:399
│      [4] _to_expr(node::Base.JuliaSyntax.SyntaxNode)
│        @ Base.JuliaSyntax /cache/build/default-amdci5-3/julialang/julia-release-1-dot-10/base/JuliaSyntax/src/expr.jl:496
│      [5] _to_expr(node::Base.JuliaSyntax.SyntaxNode) (repeats 2 times)
│        @ Base.JuliaSyntax /cache/build/default-amdci5-3/julialang/julia-release-1-dot-10/base/JuliaSyntax/src/expr.jl:495
│      [6] Expr(node::Base.JuliaSyntax.SyntaxNode)
│        @ Base.JuliaSyntax /cache/build/default-amdci5-3/julialang/julia-release-1-dot-10/base/JuliaSyntax/src/expr.jl:500
│      [7] core_parser_hook(code::String, filename::String, lineno::Int64, offset::Int64, options::Symbol)
│        @ Base.JuliaSyntax /cache/build/default-amdci5-3/julialang/julia-release-1-dot-10/base/JuliaSyntax/src/hooks.jl:209
│      [8] invoke_in_world(::UInt64, ::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
│        @ Base ./essentials.jl:921
│      [9] invoke_in_world(::UInt64, ::Any, ::Any, ::Vararg{Any})
│        @ Base ./essentials.jl:918
│     [10] (::Base.JuliaSyntax.var"#invoke_fixedworld#120"{Base.JuliaSyntax.var"#invoke_fixedworld#117#121"{…}})(::String, ::Vararg{Any}; kws::@Kwargs{})
│        @ Base.JuliaSyntax /cache/build/default-amdci5-3/julialang/julia-release-1-dot-10/base/JuliaSyntax/src/hooks.jl:118
│     [11] (::Base.JuliaSyntax.var"#invoke_fixedworld#120"{Base.JuliaSyntax.var"#invoke_fixedworld#117#121"{…}})(::String, ::Vararg{Any})
│        @ Base.JuliaSyntax /cache/build/default-amdci5-3/julialang/julia-release-1-dot-10/base/JuliaSyntax/src/hooks.jl:117
│     [12] _parse_string(text::String, filename::String, lineno::Int64, index::Int64, options::Symbol)
│        @ Base.Meta ./meta.jl:200
│     [13] #parseall#6
│        @ Base.Meta ./meta.jl:294 [inlined]
│     [14] parseall
│        @ Base.Meta ./meta.jl:293 [inlined]
│     [15] _parse_input_line_core
│        @ Base ./client.jl:174 [inlined]
│     [16] #parse_input_line#1007
│        @ Base ./client.jl:192 [inlined]
│     [17] parse_input_line
│        @ Base ./client.jl:189 [inlined]
│     [18] (::REPL.var"#93#103"{REPL.LineEditREPL, REPL.REPLHistoryProvider})(x::Any)
│        @ REPL ~/.julia/juliaup/julia-1.10.0-beta2+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:1077
│     [19] #invokelatest#2
│        @ Base ./essentials.jl:887 [inlined]
│     [20] invokelatest
│        @ Base ./essentials.jl:884 [inlined]
│     [21] (::REPL.var"#do_respond#80"{Bool, Bool, REPL.var"#93#103"{…}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
│        @ REPL ~/.julia/juliaup/julia-1.10.0-beta2+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:903
│     [22] #invokelatest#2
│        @ Base ./essentials.jl:887 [inlined]
│     [23] invokelatest
│        @ Base ./essentials.jl:884 [inlined]
│     [24] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
│        @ REPL.LineEdit ~/.julia/juliaup/julia-1.10.0-beta2+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/LineEdit.jl:2656
│     [25] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
│        @ REPL ~/.julia/juliaup/julia-1.10.0-beta2+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:1310
│     [26] (::REPL.var"#62#68"{REPL.LineEditREPL, REPL.REPLBackendRef})()
│        @ REPL ~/.julia/juliaup/julia-1.10.0-beta2+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:386
│   offset = 0
│   code = "map([3,4,5])[1] do x"
└ @ Base.JuliaSyntax /cache/build/default-amdci5-3/julialang/julia-release-1-dot-10/base/JuliaSyntax/src/hooks.jl:258
ERROR: syntax: extra token "do" after end of expression
Stacktrace:
 [1] top-level scope
   @ none:1
LilithHafner commented 1 year ago

Both of these are fixed on 1.11.0-DEV.470 (Commit d51ad06f66* (2023-09-14 20:13 UTC)) and broken on 1.10.0-beta2. They should be fixed on 1.10.0-beta3 (or -rc1), but leaving this issue open until beta3 comes out and someone confirms. https://github.com/JuliaLang/julia/pull/50928 https://github.com/JuliaLang/julia/pull/50971

c42f commented 1 year ago

I can confirm these are fixed in rc1