Skip to content

Commit

Permalink
Fix parse error with broken do syntax (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
c42f committed Jul 1, 2023
1 parent 747702b commit 6da0fc4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,7 @@ function _internal_node_to_Expr(source, srcrange, head, childranges, childheads,
# as inert QuoteNode rather than in `Expr(:quote)` quasiquote
return QuoteNode(a1)
end
elseif k == K"do"
@check length(args) == 3
elseif k == K"do" && length(args) == 3
return Expr(:do, args[1], Expr(:->, args[2], args[3]))
elseif k == K"let"
a1 = args[1]
Expand Down Expand Up @@ -439,6 +438,10 @@ function _internal_node_to_Expr(source, srcrange, head, childranges, childheads,
args[i] = ai.value
end
end
elseif k == K"wrapper"
# This should only happen for errors wrapped next to what should have
# been single statements or atoms - represent these as blocks.
headsym = :block
end

return Expr(headsym, args...)
Expand Down
2 changes: 2 additions & 0 deletions test/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@
LineNumberNode(1), Expr(:error, :b))
@test parsestmt("(x", ignore_errors=true) ==
Expr(:block, :x, Expr(:error))
@test parsestmt("x do", ignore_errors=true) ==
Expr(:block, :x, Expr(:error, Expr(:do)))
end

@testset "import" begin
Expand Down

0 comments on commit 6da0fc4

Please sign in to comment.