2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the "hack" directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
11 (*****************************************************************************)
12 (* Converts a type hint into a type *)
13 (*****************************************************************************)
18 (* Unpacking a hint for typing *)
20 let rec hint env
(p
, h
) =
21 let h = hint_ p env
h in
22 Typing_reason.Rhint p
, h
24 and hint_ p env
= function
29 if env
.Decl_env.mode
= FileInfo.Mstrict
&& h1
= None
30 then Errors.generic_array_strict p
;
31 let h1 = Option.map
h1 (hint env
) in
32 let h2 = Option.map
h2 (hint env
) in
37 | Hoption
(_
, Hprim Tvoid
) ->
38 Errors.option_return_only_typehint p `void
;
40 | Hoption
(_
, Hprim Tnoreturn
) ->
41 Errors.option_return_only_typehint p `noreturn
;
43 | Hoption
(_
, Hmixed
) ->
44 Errors.option_mixed p
;
50 let paraml = List.map hl
(hint env
) in
51 let paraml = List.map
paraml (fun x
-> None
, x
) in
52 let ret = hint env
h in
53 let arity_min = List.length
paraml in
55 then Fellipsis
arity_min
56 else Fstandard
(arity_min, arity_min)
64 ft_where_constraints
= [];
68 | Happly
((p
, "\\Tuple"), _
)
69 | Happly
((p
, "\\tuple"), _
) ->
70 Errors.tuple_syntax p
;
72 | Happly
(((_p
, c
) as id
), argl
) ->
73 Decl_hooks.dispatch_class_id_hook id None
;
74 Decl_env.add_wclass env c
;
75 let argl = List.map
argl (hint env
) in
77 | Haccess
(root_ty
, ids
) ->
78 let root_ty = hint env
root_ty in
79 Taccess
(root_ty, ids
)
81 let tyl = List.map hl
(hint env
) in
84 let fdm = ShapeMap.map
(hint env
) fdm in
85 (* Fields are only partially known, because this shape type comes from
86 * type hint - shapes that contain listed fields can be passed here, but
87 * due to structural subtyping they can also contain other fields, that we
88 * don't know about. *)
89 Tshape
(FieldsPartiallyKnown
ShapeMap.empty
, fdm)