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 (* This module implements the typing for type_structure. *)
16 module Env
= Typing_env
17 module Reason
= Typing_reason
18 module SN
= Naming_special_names
19 module TUtils
= Typing_utils
21 (* For TypeStructure<T> (which is an alias for a shape) where the type
22 parameter T is a class/enum/interface or an alias that resolves to a
23 class, we can guarantee the existence of the 'classname' field, hence
24 this function transforms the 'classname' field of the TypeStructure<T>
25 from ?classname<T> to classname<T>. *)
26 let transform_classname_ty ty
=
28 | r
, Tshape
(fk
, fdm
) ->
29 let p = Reason.to_pos r
in
30 let kClassname = Nast.SFlit
(p, "classname") in
31 let f_clsname = ShapeMap.get
kClassname fdm
in
33 | Some
(_
, Toption
(_
, Tabstract
(AKnewtype
(c
, tyl
), _
) as fty
))
34 when c
= SN.Classes.cClassname
->
35 (match List.hd tyl
with
37 (match TUtils.get_base_type tty
with
39 | (_
, Tabstract
(AKenum _
, _
)) ->
40 let fdm = ShapeMap.add
kClassname fty
fdm in
44 | _
-> ty
(* should not reach *))
45 | _
-> ty
(* should not reach *)