Skip to content

Commit e8b3650

Browse files
authored
Merge pull request #398 from julia-vscode/sp/fix-try-catch-finally
fix: correctly parse try expr catch err finally expr end
2 parents 99e12c9 + dac7651 commit e8b3650

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ version = "3.4.3"
66
[deps]
77
Tokenize = "0796e94c-ce3b-5d07-9a54-7f471281c624"
88

9+
[compat]
10+
Tokenize = "0.5.29"
11+
julia = "1"
12+
913
[extras]
1014
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1115
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
1216

13-
[compat]
14-
julia = "1"
15-
Tokenize = "0.5.29"
16-
1717
[targets]
1818
test = ["Test", "TestItemRunner"]

src/components/keywords.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ function parse_try(ps::ParseState)
457457
has_finally = false
458458
if kindof(ps.nt) === Tokens.FINALLY
459459
has_finally = true
460-
if isempty(catchblock.args) && else_trivia === nothing
460+
461+
if isempty(catchblock.args) && else_trivia === nothing && caught.head === :FALSE
461462
args[3] = EXPR(:FALSE, 0, 0, "")
462463
end
463464
push!(trivia, EXPR(next(ps)))

test/iterate/test_iterators.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,17 @@ end
866866
@test headof(x[7]) === :block
867867
@test headof(x[8]) === :END
868868

869+
x = cst"try expr catch err finally expr3 end"
870+
@test length(x) == 8
871+
@test headof(x[1]) === :TRY
872+
@test headof(x[2]) === :block
873+
@test headof(x[3]) === :CATCH
874+
@test valof(x[4]) == "err"
875+
@test headof(x[5]) === :block
876+
@test headof(x[6]) === :FINALLY
877+
@test headof(x[7]) === :block
878+
@test headof(x[8]) === :END
879+
869880
x = cst"try expr catch err expr2 finally expr3 end"
870881
@test length(x) == 8
871882
@test headof(x[1]) === :TRY

test/parser/test_keyword_blocks.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ end
8282
end
8383
""" |> test_expr
8484
@test """
85+
try
86+
f(1)
87+
catch err
88+
finally
89+
stop(f)
90+
end
91+
""" |> test_expr
92+
@test """
8593
try
8694
f(1)
8795
catch err

0 commit comments

Comments
 (0)