Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2213,7 +2213,7 @@ function parse_try(ps)
bump(ps, TRIVIA_FLAG)
parse_block(ps)
if !has_catch
#v1.8: try else end ==> (try (block) false false (error (block)) false)
#v1.8: try else x finally y end ==> (try (block) false false (error (block x)) (block y))
emit(ps, else_mark, K"error", error="Expected `catch` before `else`")
end
#v1.7: try catch ; else end ==> (try (block) false (block) (error (block)) false)
Expand Down Expand Up @@ -2241,6 +2241,10 @@ function parse_try(ps)
emit_diagnostic(ps, m, position(ps),
warning="`catch` after `finally` will execute out of order")
end
if !has_catch && !has_finally
# try x end ==> (try (block x) false false false false (error-t))
bump_invisible(ps, K"error", TRIVIA_FLAG, error="try without catch or finally")
end
bump_closing_token(ps, K"end")
emit(ps, mark, out_kind, flags)
end
Expand Down
3 changes: 2 additions & 1 deletion test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,12 @@ tests = [
"try x finally y end" => "(try (block x) false false false (block y))"
# v1.8 only
((v=v"1.8",), "try catch ; else end") => "(try (block) false (block) (block) false)"
((v=v"1.8",), "try else end") => "(try (block) false false (error (block)) false)"
((v=v"1.8",), "try else x finally y end") => "(try (block) false false (error (block x)) (block y))"
((v=v"1.7",), "try catch ; else end") => "(try (block) false (block) (error (block)) false)"
# finally before catch :-(
"try x finally y catch e z end" => "(try_finally_catch (block x) false false false (block y) e (block z))" =>
Expr(:try, Expr(:block, :x), :e, Expr(:block, :z), Expr(:block, :y))
"try x end" => "(try (block x) false false false false (error-t))"
],
JuliaSyntax.parse_imports => [
"import A as B: x" => "(import (: (error (as (. A) B)) (. x)))"
Expand Down