We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
catch
Consider this code with a non-idiomatic catch statement:
code1 = raw""" try error("Whoops") catch (e) println("Found $e") end """
Julia Formatter moves (e) inside the catch block:
(e)
using JuliaFormatter code2 = format_text(code1) @assert code2 == raw""" try error("Whoops") catch (e) println("Found $e") end """
This transformation changes the meaning of the code:
eval(Meta.parse(code1)) # Found ErrorException("Whoops") eval(Meta.parse(code2)) # ERROR: UndefVarError: `e` not defined
It seems the correct fix would be to remove the parentheses in catch e.
catch e
The text was updated successfully, but these errors were encountered:
the issue is with CSTParser
julia> x = CSTParser.parse(code1) 1:62 try 1:16 block 1:16 call 1:5 error 6:13 STRING: Whoops 17:16 FALSE: 17:44 block 17:24 brackets 17:17 e 25:44 call 25:31 println 32:41 string 32:38 STRING: Found 39:39 e julia> x = CSTParser.parse(code2) 1:60 try 1:16 block 1:16 call 1:5 error 6:13 STRING: Whoops 17:22 e 23:42 block 23:42 call 23:29 println 30:39 string 30:36 STRING: Found 37:37 e julia> Meta.parse(code1) :(try #= none:2 =# error("Whoops") catch e #= none:4 =# println("Found $(e)") end) julia> Meta.parse(code2) :(try #= none:2 =# error("Whoops") catch e #= none:4 =# println("Found $(e)") end)
In the case of (e) it thinks that's the body of the catch block
code1 is the original one with catch (e), code2 is catch e
Sorry, something went wrong.
No branches or pull requests
Consider this code with a non-idiomatic
catch
statement:Julia Formatter moves
(e)
inside the catch block:This transformation changes the meaning of the code:
It seems the correct fix would be to remove the parentheses in
catch e
.The text was updated successfully, but these errors were encountered: