diff --git a/src/julia/parser.jl b/src/julia/parser.jl index 2abed160..4bc9c288 100644 --- a/src/julia/parser.jl +++ b/src/julia/parser.jl @@ -2197,7 +2197,15 @@ 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"( ." + # Check if we should skip newlines - only for specific cases + # where we have a single type annotation like (::T) + _skip_newlines = !had_commas && num_subexprs == 1 && + !had_splat && num_semis == 0 + _needs_parse_call = if _skip_newlines + peek(ps, 2, skip_newlines=true) ∈ KSet"( ." + else + peek(ps, 2) ∈ KSet"( ." + end _is_anon_func = (!_needs_parse_call && !_parsed_call) || had_commas return (needs_parameters = _is_anon_func, is_anon_func = _is_anon_func, diff --git a/test/parser.jl b/test/parser.jl index 64ecc8ea..76567ec5 100644 --- a/test/parser.jl +++ b/test/parser.jl @@ -617,6 +617,11 @@ 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 ::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))"