Skip to content

Commit dfd1d69

Browse files
committed
Fix incomplete_tag generation with trailing whitespace (#518)
Previously we relied on the last SyntaxNode consuming all trailing whitespace when detecting incomplete syntax. However this assumption was broken by #397 and is generally fragile with respect to any extra bump_trivia() calls. Fix this by just comparing to the stream position before any bumping of remaining trivia.
1 parent 09576ca commit dfd1d69

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/hooks.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,14 @@ function core_parser_hook(code, filename::String, lineno::Int, offset::Int, opti
173173
end
174174
end
175175
parse!(stream; rule=options)
176+
pos_before_trivia = last_byte(stream)
176177
if options === :statement
177178
bump_trivia(stream)
178179
end
179180

180181
if any_error(stream)
181182
tree = build_tree(SyntaxNode, stream, first_line=lineno, filename=filename)
182-
tag = _incomplete_tag(tree, lastindex(code))
183+
tag = _incomplete_tag(tree, pos_before_trivia)
183184
if _has_v1_10_hooks
184185
exc = ParseError(stream, filename=filename, first_line=lineno,
185186
incomplete_tag=tag)

test/hooks.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ end
171171
"1, " => :other
172172
"1,\n" => :other
173173
"1, \n" => :other
174+
"f(1, " => :other
175+
"[x " => :other
176+
"( " => :other
174177

175178
# Reference parser fails to detect incomplete exprs in this case
176179
"(x for y" => :other

0 commit comments

Comments
 (0)