2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
13 (* Module checking if a type is generic, I like to use an exception for this sort
14 * of things, the code is more readable (subjective :-), and the exception never
17 module IsGeneric
: sig
18 (* Give back the position and name of a generic type parameter if found *)
19 val ty
: decl_ty
-> (Pos.t
* string) option
21 exception Found
of Pos.t
* string
26 | Tgeneric
(x
, _args
) -> raise
(Found
(get_pos t
, x
))
39 List.iter
(List.map fty
.ft_params
(fun x
-> x
.fp_type
.et_type
)) ty;
40 ty fty
.ft_ret
.et_type
;
41 (match fty
.ft_arity
with
42 | Fvariadic
{ fp_type
= var_ty
; _
} -> ty var_ty
.et_type
46 | Tintersection tyl
->
48 | Tapply
(_
, tyl
) -> List.iter tyl
ty
49 | Taccess
(t
, _
) -> ty t
51 | Tvarray_or_darray
(t1
, t2
) ->
55 | Tshape
(_
, fdm
) -> ShapeFieldMap.iter
(fun _ v
-> ty v
) fdm
60 with Found
(p
, x
) -> Some
(p
, x
)
63 let is_generic = IsGeneric.ty