Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/julia/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2199,13 +2199,18 @@ function parse_function_signature(ps::ParseState, is_function::Bool)
is_empty_tuple = peek(ps, skip_newlines=true) == K")"
opts = parse_brackets(ps, K")") do had_commas, had_splat, num_semis, num_subexprs
_parsed_call = was_eventually_call(ps)
_needs_parse_call = peek(ps, 2) ∈ KSet"( ."
_maybe_grouping_parens = !had_commas && !had_splat && num_semis == 0 && num_subexprs == 1
# Skip intervening newlines only when the parentheses hold a single
# expression, which is the ambiguous case between a name like (::T)
# and an anonymous function parameter list.
next_kind = peek(ps, 2, skip_newlines=_maybe_grouping_parens)
_needs_parse_call = next_kind ∈ KSet"( ."
_is_anon_func = (!_needs_parse_call && !_parsed_call) || had_commas
return (needs_parameters = _is_anon_func,
is_anon_func = _is_anon_func,
parsed_call = _parsed_call,
needs_parse_call = _needs_parse_call,
maybe_grouping_parens = !had_commas && !had_splat && num_semis == 0 && num_subexprs == 1)
return (needs_parameters = _is_anon_func,
is_anon_func = _is_anon_func,
parsed_call = _parsed_call,
needs_parse_call = _needs_parse_call,
maybe_grouping_parens = _maybe_grouping_parens)
end
is_anon_func = opts.is_anon_func
parsed_call = opts.parsed_call
Expand Down
7 changes: 7 additions & 0 deletions test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,13 @@ tests = [
"function (::g(x))() end" => "(function (call (parens (::-pre (call g x)))) (block))"
"function (f::T{g(i)})() end" => "(function (call (parens (::-i f (curly T (call g i))))) (block))"
"function (::T)() end" => "(function (call (parens (::-pre T))) (block))"
"function (\n ::T\n )() end" => "(function (call (parens (::-pre T))) (block))"
"function (\n x::T\n )() end" => "(function (call (parens (::-i x T))) (block))"
"function (\n f\n )() end" => "(function (call (parens f)) (block))"
"function (\n A\n ).f() end" => "(function (call (. (parens A) f)) (block))"
"function (\n ::T\n )(x, y) end" => "(function (call (parens (::-pre T)) x y) (block))"
"function (\n f::T{g(i)}\n )() end" => "(function (call (parens (::-i f (curly T (call g i))))) (block))"
"function (\n x, y\n ) x + y end" => "(function (tuple-p x y) (block (call-i x + y)))"
"function (:*=(f))() end" => "(function (call (parens (call (quote-: *=) f))) (block))"
"function begin() end" => "(function (call (error begin)) (block))"
"function f() end" => "(function (call f) (block))"
Expand Down
Loading