Don't detach handler after onError
[hiphop-php.git] / hphp / hack / src / typing / typing_func_terminality.ml
blobdc37b7419eebed0cd89a9040598995de2cd85fbc
1 (*
2 * Copyright (c) 2015, 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 open Typing_defs
13 module Env = Typing_env
14 module Cls = Folded_class
16 (* Not adding a Typing_dep here because it will be added when the
17 * Nast is fully processed (by the caller of this code) *)
18 let get_fun ctx name =
19 match Decl_provider.get_fun ctx name |> Decl_entry.to_option with
20 | Some { fe_type; _ } -> begin
21 match get_node fe_type with
22 | Tfun ft -> Some ft
23 | _ -> None
24 end
25 | _ -> None
27 let get_static_meth
28 (ctx : Provider_context.t) (cls_name : string) (meth_name : string) =
29 match Decl_provider.get_class ctx cls_name with
30 | Decl_entry.DoesNotExist
31 | Decl_entry.NotYetAvailable ->
32 None
33 | Decl_entry.Found cls -> begin
34 match Cls.get_smethod cls meth_name with
35 | None -> None
36 | Some { Typing_defs.ce_type = (lazy ty); _ } -> begin
37 match get_node ty with
38 | Tfun fty -> Some fty
39 | _ -> None
40 end
41 end
43 let funopt_is_noreturn = function
44 | Some { ft_ret; _ } -> is_prim Tnoreturn ft_ret
45 | _ -> false
47 let static_meth_is_noreturn env ci meth_id =
48 let class_name =
49 match ci with
50 | CI cls_id -> Some (snd cls_id)
51 | CIself
52 | CIstatic ->
53 Env.get_self_id env
54 | CIparent -> Env.get_parent_id env
55 | CIexpr _ -> None
56 (* we declared the types, but didn't check the bodies yet
57 so can't tell anything here *)
59 match class_name with
60 | Some class_name ->
61 funopt_is_noreturn
62 (get_static_meth (Env.get_ctx env) class_name (snd meth_id))
63 | None -> false
65 let typed_expression_exits (ty, _, _e) = is_type_no_return (get_node ty)
67 let expression_exits env (_, _, e) =
68 match e with
69 | Call { func = (_, _, Id (_, fun_name)); _ } ->
70 funopt_is_noreturn @@ get_fun (Env.get_ctx env) fun_name
71 | Call { func = (_, _, Class_const ((_, _, ci), meth_id)); _ } ->
72 static_meth_is_noreturn env ci meth_id
73 | _ -> false
75 let is_noreturn env =
76 let (_env, ret_ty) =
77 Env.expand_type env (Env.get_return env).Typing_env_return_info.return_type
79 is_prim Tnoreturn ret_ty