solved some TODOs about Tgeneric type arguments (2)
[hiphop-php.git] / hphp / hack / src / typing / nast_check / interface_check.ml
blob4878c2021c261e18f18553a0e1faabbf134bc894
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 let enforce_no_body m =
14 match m.m_body.fb_ast with
15 | [] -> ()
16 | _ -> Errors.abstract_body (fst m.m_name)
18 let check_interface c =
19 List.iter c.c_uses (fun (p, _) -> Errors.interface_use_trait p);
21 let (statics, vars) = split_vars c in
22 begin
23 match vars with
24 | hd :: _ ->
25 let pos = fst hd.cv_id in
26 Errors.interface_with_member_variable pos
27 | _ -> ()
28 end;
30 begin
31 match statics with
32 | hd :: _ ->
33 let pos = fst hd.cv_id in
34 Errors.interface_with_static_member_variable pos
35 | _ -> ()
36 end;
38 (* make sure interfaces do not contain partially abstract type constants *)
39 List.iter c.c_typeconsts (fun tc ->
41 Option.is_some tc.c_tconst_constraint && Option.is_some tc.c_tconst_type
42 then
43 Errors.interface_with_partial_typeconst (fst tc.c_tconst_name));
45 (* make sure that interfaces only have empty public methods *)
46 List.iter ~f:enforce_no_body c.c_methods
48 let handler =
49 object
50 inherit Nast_visitor.handler_base
52 method! at_class_ _ c =
53 if Ast_defs.(equal_class_kind c.c_kind Cinterface) then check_interface c
54 end