Skip to content

Commit 6da0fc4

Browse files
authored
Fix parse error with broken do syntax (#323)
1 parent 747702b commit 6da0fc4

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/expr.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ function _internal_node_to_Expr(source, srcrange, head, childranges, childheads,
395395
# as inert QuoteNode rather than in `Expr(:quote)` quasiquote
396396
return QuoteNode(a1)
397397
end
398-
elseif k == K"do"
399-
@check length(args) == 3
398+
elseif k == K"do" && length(args) == 3
400399
return Expr(:do, args[1], Expr(:->, args[2], args[3]))
401400
elseif k == K"let"
402401
a1 = args[1]
@@ -439,6 +438,10 @@ function _internal_node_to_Expr(source, srcrange, head, childranges, childheads,
439438
args[i] = ai.value
440439
end
441440
end
441+
elseif k == K"wrapper"
442+
# This should only happen for errors wrapped next to what should have
443+
# been single statements or atoms - represent these as blocks.
444+
headsym = :block
442445
end
443446

444447
return Expr(headsym, args...)

test/expr.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@
700700
LineNumberNode(1), Expr(:error, :b))
701701
@test parsestmt("(x", ignore_errors=true) ==
702702
Expr(:block, :x, Expr(:error))
703+
@test parsestmt("x do", ignore_errors=true) ==
704+
Expr(:block, :x, Expr(:error, Expr(:do)))
703705
end
704706

705707
@testset "import" begin

0 commit comments

Comments
 (0)