solved some TODOs about Tgeneric type arguments (2)
[hiphop-php.git] / hphp / hack / src / typing / nast_check / attribute_arity_check.ml
blob6088c19606fd7a3b777a9fc38674d139cf7d75de
1 (*
2 * Copyright (c) 2020, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
8 *)
10 open Aast
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 =
19 match v with
20 | FVvariadicArg param -> Some param.param_pos
21 | FVellipsis p -> Some p
22 | FVnonVariadic -> None
24 let handler =
25 object
26 inherit Nast_visitor.handler_base
28 method! at_fun_ _ f =
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
32 | [] -> ()
33 | param :: _ -> Errors.entrypoint_arguments param.param_pos);
34 match variadic_pos f.f_variadic with
35 | Some p -> Errors.entrypoint_arguments p
36 | None -> ()
37 end;
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
42 | None -> ()
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
49 then
50 match variadic_pos m.m_variadic with
51 | Some p -> Errors.variadic_memoize p
52 | None -> ()
53 end