Move io_tests to folly/io/async/test
[hiphop-php.git] / hphp / hack / src / typing / nast_check / class_tparams_check.ml
blob76404c21501f4aa4fd7b381c715fccbeab63ad87
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
13 type ctx = { class_tparams: Nast.tparam list }
15 let visitor =
16 object (this)
17 inherit [ctx] Nast_visitor.iter_with_state as super
19 method! on_hint (env, state) (pos, h) =
20 begin
21 match h with
22 | Habstr (tp_name, args) ->
23 List.iter
24 state.class_tparams
25 ~f:(fun { tp_name = (c_tp_pos, c_tp_name); _ } ->
26 if String.equal c_tp_name tp_name then
27 Errors.add_error
28 Nast_check_error.(
29 to_user_error
30 @@ Typeconst_depends_on_external_tparam
31 { pos; ext_pos = c_tp_pos; ext_name = c_tp_name }));
32 List.iter args ~f:(this#on_hint (env, state))
33 | _ -> ()
34 end;
35 super#on_hint (env, state) (pos, h)
36 end
38 let handler =
39 object
40 inherit Nast_visitor.handler_base
42 method! at_class_ env c =
43 let state = { class_tparams = c.c_tparams } in
44 let on_hint = visitor#on_hint (env, state) in
45 List.iter c.c_typeconsts ~f:(fun t ->
46 match t.c_tconst_kind with
47 | TCAbstract
49 c_atc_as_constraint = a;
50 c_atc_super_constraint = s;
51 c_atc_default = d;
52 } ->
53 Option.iter a ~f:on_hint;
54 Option.iter s ~f:on_hint;
55 Option.iter d ~f:on_hint
56 | TCConcrete { c_tc_type = t } -> on_hint t)
57 end