@@ -2016,6 +2016,7 @@ end
20162016# Parse function and macro definitions
20172017function parse_function_signature (ps:: ParseState , is_function:: Bool )
20182018 is_anon_func = false
2019+ parsed_call = false
20192020
20202021 mark = position (ps)
20212022 if ! is_function
@@ -2053,17 +2054,7 @@ function parse_function_signature(ps::ParseState, is_function::Bool)
20532054 parsed_call = _parsed_call)
20542055 end
20552056 is_anon_func = opts. is_anon_func
2056- if opts. parsed_call
2057- # Compat: Ugly case where extra parentheses existed and we've
2058- # already parsed the whole signature.
2059- # function (f() where T) end ==> (function (where (call f) T) (block))
2060- # function (f()::S) end ==> (function (:: (call f) S) (block))
2061- #
2062- # TODO : Warn for use of parens? The precedence of `::` and
2063- # `where` don't work inside parens so this is a bit of a syntax
2064- # oddity/aberration.
2065- return true
2066- end
2057+ parsed_call = opts. parsed_call
20672058 if is_anon_func
20682059 # function (x) body end ==> (function (tuple x) (block body))
20692060 # function (x::f()) end ==> (function (tuple (:: x (call f))) (block))
@@ -2099,10 +2090,10 @@ function parse_function_signature(ps::ParseState, is_function::Bool)
20992090 end
21002091 end
21012092 end
2102- if peek (ps, skip_newlines= true ) == K " end" && ! is_anon_func
2093+ if peek (ps, skip_newlines= true ) == K " end" && ! is_anon_func && ! parsed_call
21032094 return false
21042095 end
2105- if ! is_anon_func
2096+ if ! is_anon_func && ! parsed_call
21062097 # Parse function argument list
21072098 # function f(x,y) end ==> (function (call f x y) (block))
21082099 # function f{T}() end ==> (function (call (curly f T)) (block))
@@ -2129,6 +2120,19 @@ function parse_function_signature(ps::ParseState, is_function::Bool)
21292120 parse_where_chain (ps, mark)
21302121 end
21312122 # function f()::S where T end ==> (function (where (:: (call f) S) T) (block))
2123+ #
2124+ # Ugly cases for compat where extra parentheses existed and we've
2125+ # already parsed at least the call part of the signature
2126+ #
2127+ # function (f() where T) end ==> (function (where (call f) T) (block))
2128+ # function (f()) where T end ==> (function (where (call f) T) (block))
2129+ # function (f() where T) where U end ==> (function (where (where (call f) T) U) (block))
2130+ # function (f()::S) end ==> (function (:: (call f) S) (block))
2131+ # function ((f()::S) where T) end ==> (function (where (:: (call f) S) T) (block))
2132+ #
2133+ # TODO : Warn for use of parens? The precedence of `::` and
2134+ # `where` don't work inside parens so this is a bit of a syntax
2135+ # oddity/aberration.
21322136 return true
21332137end
21342138
0 commit comments