2 * Copyright (c) 2020, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
12 let has_attribute (name
: string) (attrs
: Nast.user_attribute list
) : bool =
13 let matches_name { ua_name
= (_
, attr_name
); _
} =
14 String.equal attr_name name
16 List.exists
matches_name attrs
18 let variadic_pos v
: pos
option =
20 | FVvariadicArg param
-> Some param
.param_pos
21 | FVellipsis p
-> Some p
22 | FVnonVariadic
-> None
26 inherit Nast_visitor.handler_base
29 (* Ban arguments on functions with the __EntryPoint attribute. *)
30 if has_attribute "__EntryPoint" f
.f_user_attributes
then begin
31 (match f
.f_params
with
33 | param
:: _
-> Errors.entrypoint_arguments param
.param_pos
);
34 match variadic_pos f
.f_variadic
with
35 | Some p
-> Errors.entrypoint_arguments p
38 (* Ban variadic arguments on memoized functions. *)
39 if has_attribute "__Memoize" f
.f_user_attributes
then
40 match variadic_pos f
.f_variadic
with
41 | Some p
-> Errors.variadic_memoize p
44 method! at_method_ _ m
=
45 (* Ban variadic arguments on memoized methods. *)
47 has_attribute "__Memoize" m
.m_user_attributes
48 || has_attribute "__MemoizeLSB" m
.m_user_attributes
50 match variadic_pos m
.m_variadic
with
51 | Some p
-> Errors.variadic_memoize p