@@ -2143,36 +2143,13 @@ macro inferred(allow, ex)
2143
2143
_inferred (ex, __module__, allow)
2144
2144
end
2145
2145
function _inferred (ex, mod, allow = :(Union{}))
2146
- if Meta. isexpr (ex, :ref )
2147
- ex = Expr (:call , :getindex , ex. args... )
2148
- end
2149
- Meta. isexpr (ex, :call )|| error (" @inferred requires a call expression" )
2150
- farg = ex. args[1 ]
2151
- if isa (farg, Symbol) && farg != = :.. && first (string (farg)) == ' .'
2152
- farg = Symbol (string (farg)[2 : end ])
2153
- ex = Expr (:call , GlobalRef (Test, :_materialize_broadcasted ),
2154
- farg, ex. args[2 : end ]. .. )
2155
- end
2146
+ Meta. isexpr (ex, (:call , :ref , :do )) || error (" @inferred requires a call expression" )
2156
2147
result = let ex = ex
2157
2148
quote
2158
2149
let allow = $ (esc (allow))
2159
2150
allow isa Type || throw (ArgumentError (" @inferred requires a type as second argument" ))
2160
- $ (if any (@nospecialize (a)-> (Meta. isexpr (a, :kw ) || Meta. isexpr (a, :parameters )), ex. args)
2161
- # Has keywords
2162
- args = gensym ()
2163
- kwargs = gensym ()
2164
- quote
2165
- $ (esc (args)), $ (esc (kwargs)), result = $ (esc (Expr (:call , _args_and_call, ex. args[2 : end ]. .. , ex. args[1 ])))
2166
- inftype = $ (gen_call_with_extracted_types (mod, Base. infer_return_type, :($ (ex. args[1 ])($ (args). .. ; $ (kwargs). .. )); is_source_reflection = false ))
2167
- end
2168
- else
2169
- # No keywords
2170
- quote
2171
- args = ($ ([esc (ex. args[i]) for i = 2 : length (ex. args)]. .. ),)
2172
- result = $ (esc (ex. args[1 ]))(args... )
2173
- inftype = Base. infer_return_type ($ (esc (ex. args[1 ])), Base. typesof (args... ))
2174
- end
2175
- end )
2151
+ result = $ (esc (ex))
2152
+ inftype = $ (gen_call_with_extracted_types (mod, Base. infer_return_type, ex; is_source_reflection = false ))
2176
2153
rettype = result isa Type ? Type{result} : typeof (result)
2177
2154
rettype <: allow || rettype == typesplit (inftype, allow) || error (" return type $rettype does not match inferred return type $inftype " )
2178
2155
result
0 commit comments