Avoid using decl_class_type wherever possible
[hiphop-php.git] / hphp / hack / src / typing / tast_check / abstract_class_check.ml
blob3702ab448f5127e8909caaaad23cfab4fc599cd3
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 Tast
11 open Core_kernel
13 module Env = Tast_env
14 module Cls = Typing_classes_heap
15 module SN = Naming_special_names
17 let check_expr env (pos, e) =
18 match e with
19 | Class_const ((_, CIparent), ((_, construct)))
20 when construct = SN.Members.__construct ->
21 let tenv = Env.tast_env_as_typing_env env in
22 begin match Env.get_class env (Typing_env.get_parent_id tenv) with
23 | Some parent_class when Cls.kind parent_class = Ast.Cabstract ->
24 if fst (Cls.construct parent_class) = None then
25 Errors.parent_abstract_call construct (fst pos) (Cls.pos parent_class);
26 | _ -> ()
27 end
28 | _ -> ()
30 let check_method_body env m =
31 let named_body = m.m_body in
32 if m.m_abstract && named_body.fb_ast <> []
33 then Errors.abstract_with_body m.m_name;
34 let tenv = Env.tast_env_as_typing_env env in
35 if not (Typing_env.is_decl tenv) && not m.m_abstract && named_body.fb_ast = []
36 then Errors.not_abstract_without_body m.m_name
38 let check_class _ c =
39 if c.c_kind = Ast.Cabstract && c.c_final then begin
40 let err m =
41 Errors.nonstatic_method_in_abstract_final_class (fst m.m_name) in
42 List.iter c.c_methods err;
43 Option.iter c.c_constructor err
44 end
46 let handler = object
47 inherit Tast_visitor.handler_base
49 method! at_expr env e = check_expr env e
51 method! at_method_ env m = check_method_body env m
53 method! at_class_ env c = check_class env c
54 end