Skip to content

Commit

Permalink
Fix crash when parsing malformed function(where (#388)
Browse files Browse the repository at this point in the history
When word operators are parsed as atoms (ie, identifiers), the kind
should be remapped as such. This fixes a crash when parsing
`function(where` because `was_eventually_call` assumes that a kind of
`K"where"` implies an internal node.
  • Loading branch information
c42f committed Nov 10, 2023
1 parent a37ed8a commit 328905f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3464,6 +3464,9 @@ function parse_atom(ps::ParseState, check_identifiers=true)
# xx ==> xx
# x₁ ==> x₁
bump(ps)
elseif is_word_operator(leading_kind)
# where=1 ==> (= where 1)
bump(ps, remap_kind=K"Identifier")
elseif is_operator(leading_kind)
# + ==> +
# .+ ==> (. +)
Expand Down
6 changes: 5 additions & 1 deletion test/fuzz_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,11 @@ function try_hook_failure(str)
try
test_logger = Test.TestLogger()
Logging.with_logger(test_logger) do
Meta_parseall(str)
try
Meta_parseall(str)
catch exc
exc isa Meta.ParseError || exc isa JuliaSyntax.ParseError || rethrow()
end
end
if !isempty(test_logger.logs)
return str
Expand Down
1 change: 1 addition & 0 deletions test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ parsestmt_test_specs = [
"|(&\nfunction" => "(call | (& (function (error (error)) (block (error)) (error-t))) (error-t))"
"@(" => "(macrocall (parens (error-t)))"
"x = @(" => "(= x (macrocall (parens (error-t))))"
"function(where" => "(function (tuple-p where (error-t)) (block (error)) (error-t))"
# Contextual keyword pairs must not be separated by newlines even within parens
"(abstract\ntype X end)" => "(wrapper (parens abstract (error-t type X)) (error-t end ✘))"
"(mutable\nstruct X end)" => "(wrapper (parens mutable (error-t struct X)) (error-t end ✘))"
Expand Down

0 comments on commit 328905f

Please sign in to comment.