solved some TODOs about Tgeneric type arguments (2)
[hiphop-php.git] / hphp / hack / src / typing / nast_check / inout_check.ml
blob6ead4893f434db198408c07a1529580001b541a2
1 (*
2 * Copyright (c) 2018, 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 Hh_prelude
11 open Aast
12 module SN = Naming_special_names
14 let check_param _env params p user_attributes f_type name =
15 List.iter params (fun param ->
16 match param.param_callconv with
17 | Some Ast_defs.Pinout ->
18 let pos = param.param_pos in
19 if Ast_defs.(equal_fun_kind f_type FCoroutine) then
20 Errors.inout_params_in_coroutine pos;
21 if SSet.mem name SN.Members.as_set then Errors.inout_params_special pos
22 | None -> ());
23 let inout =
24 List.find params (fun x ->
25 Option.equal
26 Ast_defs.equal_param_kind
27 x.param_callconv
28 (Some Ast_defs.Pinout))
30 match inout with
31 | Some param ->
33 Naming_attributes.mem2
34 SN.UserAttributes.uaMemoize
35 SN.UserAttributes.uaMemoizeLSB
36 user_attributes
37 then
38 Errors.inout_params_memoize p param.param_pos
39 | _ -> ()
41 let is_dynamic_call func_expr =
42 match func_expr with
43 (* regular function call, e.g. func() *)
44 | Id _ -> false
45 (* instance method call, e.g. $x->method() *)
46 | Obj_get (_, (_, Id _), _) -> false
47 (* static method call, e.g. Foo::method() *)
48 | Class_const (_, _) -> false
49 (* everything else *)
50 | _ -> true
52 let check_callconv_expr e =
53 let rec check_callconv_expr_helper e1 =
54 match snd e1 with
55 | Lvar (_, x)
56 when not
57 ( String.equal (Local_id.to_string x) SN.SpecialIdents.this
58 || String.equal
59 (Local_id.to_string x)
60 SN.SpecialIdents.dollardollar ) ->
62 | Array_get (e2, Some _) -> check_callconv_expr_helper e2
63 | _ -> Errors.inout_argument_bad_expr (fst e)
65 check_callconv_expr_helper e
67 let handler =
68 object
69 inherit Nast_visitor.handler_base
71 method! at_fun_ env f =
72 let (p, name) = f.f_name in
73 let f_type = f.f_fun_kind in
74 check_param env f.f_params p f.f_user_attributes f_type name
76 method! at_method_ env m =
77 let (p, name) = m.m_name in
78 let f_type = m.m_fun_kind in
79 check_param env m.m_params p m.m_user_attributes f_type name
81 method! at_expr _ (_, e) =
82 match e with
83 | Callconv (_, e) -> check_callconv_expr e
84 | _ -> ()
85 end