Skip to content

Commit 491f3f7

Browse files
committed
Fix multiline function signature parsing
Multiline function signatures with type annotations were incorrectly parsed as tuples instead of calls when newlines appeared between parentheses. For example: ```julia function ( ::A )() end ``` was parsed as `(function (tuple ...) (block))` instead of the correct `(function (call (parens ...)) (block))`, inconsistent with the single-line version `function (::A)() end`. The issue was in parse_function_signature where `peek(ps, 2)` was used to detect if a call pattern follows the closing parenthesis, but this didn't skip newlines. Changed to `peek(ps, 2, skip_newlines=true)` to properly detect the opening parenthesis of the argument list even when separated by whitespace. 🤖 Generated with [Claude Code](https://claude.ai/code)
1 parent 2e8d590 commit 491f3f7

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/julia/parser.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,7 @@ function parse_function_signature(ps::ParseState, is_function::Bool)
21972197
is_empty_tuple = peek(ps, skip_newlines=true) == K")"
21982198
opts = parse_brackets(ps, K")") do had_commas, had_splat, num_semis, num_subexprs
21992199
_parsed_call = was_eventually_call(ps)
2200-
_needs_parse_call = peek(ps, 2) KSet"( ."
2200+
_needs_parse_call = peek(ps, 2, skip_newlines=true) KSet"( ."
22012201
_is_anon_func = (!_needs_parse_call && !_parsed_call) || had_commas
22022202
return (needs_parameters = _is_anon_func,
22032203
is_anon_func = _is_anon_func,

test/parser.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ tests = [
617617
"function (::g(x))() end" => "(function (call (parens (::-pre (call g x)))) (block))"
618618
"function (f::T{g(i)})() end" => "(function (call (parens (::-i f (curly T (call g i))))) (block))"
619619
"function (::T)() end" => "(function (call (parens (::-pre T))) (block))"
620+
"function (\n ::T\n )() end" => "(function (call (parens (::-pre T))) (block))"
620621
"function (:*=(f))() end" => "(function (call (parens (call (quote-: *=) f))) (block))"
621622
"function begin() end" => "(function (call (error begin)) (block))"
622623
"function f() end" => "(function (call f) (block))"

0 commit comments

Comments
 (0)