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

Crash formatting errors arising from parseatom #314

Closed
c42f opened this issue Jun 22, 2023 · 1 comment · Fixed by #317
Closed

Crash formatting errors arising from parseatom #314

c42f opened this issue Jun 22, 2023 · 1 comment · Fixed by #317

Comments

@c42f
Copy link
Member

c42f commented Jun 22, 2023

Printing errors arising from parseatom sometimes fails, but not parsestmt or parseall.

MWE:

julia> exc = try JuliaSyntax.parseatom(Expr, ")") ; catch e ; e end
JuliaSyntax.ParseError(SourceFile("", 0, nothing, 1, [1, 1]), JuliaSyntax.Diagnostic[JuliaSyntax.Diagnostic(1, 0, :error, "unexpected `)`"), JuliaSyntax.Diagnostic(1, 1, :error, "unexpected text after parsing atom")], :none)

julia> showerror(stdout, exc)
ParseError:
# Error @ line 1:1
ERROR: BoundsError: attempt to access empty SubString{String} at index [0]
Stacktrace:
 [1] checkbounds(s::SubString{String}, I::Int64)
   @ Base ./strings/basic.jl:216 [inlined]
 [2] getindex(s::SubString{String}, i::Int64)
   @ Base ./strings/substring.jl:91
 [3] getindex(source::SourceFile, i::Int64)
   @ JuliaSyntax ~/.julia/dev/JuliaSyntax/src/source_files.jl:120
 [4] highlight(io::Base.TTY, source::SourceFile, range::UnitRange{…}; color::Tuple{…}, context_lines_before::Int64, context_lines_inner::Int64, context_lines_after::Int64, note::String, notecolor::Symbol)
   @ JuliaSyntax ~/.julia/dev/JuliaSyntax/src/source_files.jl:222
 [5] kwcall(::NamedTuple, ::typeof(JuliaSyntax.highlight), io::IO, source::SourceFile, range::UnitRange)
   @ JuliaSyntax ~/.julia/dev/JuliaSyntax/src/source_files.jl:190 [inlined]
 [6] show_diagnostic(io::Base.TTY, diagnostic::JuliaSyntax.Diagnostic, source::SourceFile)
   @ JuliaSyntax ~/.julia/dev/JuliaSyntax/src/diagnostics.jl:76
 [7] showerror(io::Base.TTY, err::JuliaSyntax.ParseError; limit::Bool)
   @ JuliaSyntax ~/.julia/dev/JuliaSyntax/src/parser_api.jl:21 [inlined]
 [8] showerror(io::Base.TTY, err::JuliaSyntax.ParseError)
   @ JuliaSyntax ~/.julia/dev/JuliaSyntax/src/parser_api.jl:18
 [9] top-level scope
   @ REPL[108]:1
Some type information was truncated. Use `show(err)` to see complete types.

Found in JuliaLang/julia#50245

@c42f
Copy link
Member Author

c42f commented Jun 22, 2023

Actually this can also happen with parsestmt if there's trailing text

julia> exc = try JuliaSyntax.parsestmt(Expr, "x\nz") ; catch e ; e end
JuliaSyntax.ParseError(SourceFile("x", 0, nothing, 1, [1, 2]), JuliaSyntax.Diagnostic[JuliaSyntax.Diagnostic(3, 3, :error, "unexpected text after parsing statement")], :none)

julia> showerror(stdout, exc)
ParseError:
ERROR: BoundsError: attempt to access 1-codeunit SubString{String} at index [2]
Stacktrace:
 [1] _nextind_str(s::SubString{String}, i::Int64)
   @ Base ./strings/string.jl:177
 [2] nextind(s::SubString{String}, i::Int64)
   @ Base ./strings/substring.jl:104 [inlined]
 [3] source_location(source::SourceFile, byte_index::Int64)
   @ JuliaSyntax ~/.julia/dev/JuliaSyntax/src/source_files.jl:64
 [4] show_diagnostic(io::Base.TTY, diagnostic::JuliaSyntax.Diagnostic, source::SourceFile)
   @ JuliaSyntax ~/.julia/dev/JuliaSyntax/src/diagnostics.jl:61
 [5] show_diagnostics(io::Base.TTY, diagnostics::Vector{JuliaSyntax.Diagnostic}, source::SourceFile)
   @ JuliaSyntax ~/.julia/dev/JuliaSyntax/src/diagnostics.jl:86
 [6] showerror(io::Base.TTY, err::JuliaSyntax.ParseError)
   @ JuliaSyntax ~/.julia/dev/JuliaSyntax/src/parser_api.jl:20
 [7] top-level scope
   @ REPL[122]:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant