Remove sub_type parameter from Typing_coercion
[hiphop-php.git] / hphp / hack / src / typing / typing_ops.ml
blob37b9e3bd948bae008a4bbd3a914100b5b18d8a5f
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 Core_kernel
11 module Reason = Typing_reason
12 module Env = Typing_env
13 module MakeType = Typing_make_type
15 (*****************************************************************************)
16 (* Exporting. *)
17 (*****************************************************************************)
19 (* Tries to add constraint that ty_sub is subtype of ty_super in envs *)
20 let sub_type p ur env ty_sub ty_super on_error =
21 Typing_log.(
22 log_with_level env "sub" 1 (fun () ->
23 log_types
25 env
27 Log_head
28 ( "Typing_ops.sub_type",
29 [Log_type ("ty_sub", ty_sub); Log_type ("ty_super", ty_super)]
31 ]));
32 Errors.try_add_err
34 (Reason.string_of_ureason ur)
35 (fun () -> Typing_subtype.sub_type env ty_sub ty_super on_error)
36 (fun () -> env)
38 let sub_type_decl p ur env ty_sub ty_super =
39 let (env, ty_super) = Typing_utils.localize_with_self env ty_super in
40 let (env, ty_sub) = Typing_utils.localize_with_self env ty_sub in
41 ignore (sub_type p ur env ty_sub ty_super Errors.unify_error)
43 (* Ensure that types are equivalent i.e. subtypes of each other *)
44 let unify_decl p ur env ty1 ty2 =
45 let (env, ty1) = Typing_utils.localize_with_self env ty1 in
46 let (env, ty2) = Typing_utils.localize_with_self env ty2 in
47 ignore (sub_type p ur env ty2 ty1 Errors.unify_error);
48 ignore (sub_type p ur env ty1 ty2 Errors.unify_error)