Skip to content

Commit be5d02c

Browse files
committed
fix empty catch handling
1 parent 76a1f15 commit be5d02c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/components/keywords.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ function parse_try(ps::ParseState)
413413
# else block
414414
if kindof(ps.nt) === Tokens.ELSE
415415
if isempty(catchblock.args)
416-
args[3] = EXPR(:FALSE, 0, 0, "")
416+
args[3] = EXPR(:block, 0, 0, "")
417417
end
418418
else_trivia = EXPR(next(ps))
419419
else_arg = EXPR(:block, parse_block(ps, EXPR[], (Tokens.FINALLY,Tokens.END)))
@@ -423,7 +423,7 @@ function parse_try(ps::ParseState)
423423
if kindof(ps.nt) === Tokens.FINALLY
424424
has_finally = true
425425
if isempty(catchblock.args)
426-
args[3] = EXPR(:FALSE, 0, 0, "")
426+
args[3] = EXPR(:block, 0, 0, "")
427427
end
428428
push!(trivia, EXPR(next(ps)))
429429
push!(args, EXPR(:block, parse_block(ps)))

test/parser.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,13 @@ end
635635
stop(f)
636636
end
637637
""" |> test_expr
638+
@test """try
639+
f(1)
640+
catch
641+
else
642+
stop(f)
643+
end
644+
""" |> test_expr
638645
@test """try
639646
f(1)
640647
catch err
@@ -645,6 +652,13 @@ end
645652
foo
646653
end
647654
""" |> test_expr
655+
# the most useless try catch ever:
656+
@test """try
657+
catch
658+
else
659+
finally
660+
end
661+
""" |> test_expr
648662
end
649663
end
650664
@testset "For" begin

0 commit comments

Comments
 (0)