Skip to content

Commit a6b94d2

Browse files
authored
Fix crash when parsing malformed function(where (#388)
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.
1 parent 5757535 commit a6b94d2

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/parser.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,6 +3475,9 @@ function parse_atom(ps::ParseState, check_identifiers=true)
34753475
# xx ==> xx
34763476
# x₁ ==> x₁
34773477
bump(ps)
3478+
elseif is_word_operator(leading_kind)
3479+
# where=1 ==> (= where 1)
3480+
bump(ps, remap_kind=K"Identifier")
34783481
elseif is_operator(leading_kind)
34793482
# + ==> +
34803483
# .+ ==> (. +)

test/fuzz_test.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,11 @@ function try_hook_failure(str)
905905
try
906906
test_logger = Test.TestLogger()
907907
Logging.with_logger(test_logger) do
908-
Meta_parseall(str)
908+
try
909+
Meta_parseall(str)
910+
catch exc
911+
exc isa Meta.ParseError || exc isa JuliaSyntax.ParseError || rethrow()
912+
end
909913
end
910914
if !isempty(test_logger.logs)
911915
return str

test/parser.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ parsestmt_test_specs = [
10041004
"|(&\nfunction" => "(call | (& (function (error (error)) (block (error)) (error-t))) (error-t))"
10051005
"@(" => "(macrocall (parens (error-t)))"
10061006
"x = @(" => "(= x (macrocall (parens (error-t))))"
1007+
"function(where" => "(function (tuple-p where (error-t)) (block (error)) (error-t))"
10071008
# Contextual keyword pairs must not be separated by newlines even within parens
10081009
"(abstract\ntype X end)" => "(wrapper (parens abstract (error-t type X)) (error-t end ✘))"
10091010
"(mutable\nstruct X end)" => "(wrapper (parens mutable (error-t struct X)) (error-t end ✘))"

0 commit comments

Comments
 (0)