Remove Tarray from the typechecker
[hiphop-php.git] / hphp / hack / src / typing / typing_reified_check.ml
blobc3a3fca386924c40d655ae518f5f6ef41b33fa31
1 (*
2 * Copyright (c) 2018, 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 Typing_defs
12 open Type_validator
13 module Env = Tast_env
14 module SN = Naming_special_names
15 module UA = SN.UserAttributes
16 module Cls = Decl_provider.Class
17 module Nast = Aast
19 let validator =
20 object (this)
21 inherit type_validator as super
23 method! on_tapply acc r (p, h) tyl =
24 if String.equal h SN.Classes.cTypename then
25 this#invalid acc r "a typename"
26 else if String.equal h SN.Classes.cClassname then
27 this#invalid acc r "a classname"
28 else if
29 String.equal h SN.Typehints.wildcard
30 && not (Env.get_allow_wildcards acc.env)
31 then
32 this#invalid acc r "a wildcard"
33 else
34 super#on_tapply acc r (p, h) tyl
36 method! on_tgeneric acc r t _tyargs =
37 (* Ignoring type aguments: If there were any, then this generic variable isn't allowed to be
38 reified anyway *)
39 (* TODO(T70069116) actually implement that check *)
40 match Env.get_reified acc.env t with
41 | Nast.Erased -> this#invalid acc r "not reified"
42 | Nast.SoftReified -> this#invalid acc r "soft reified"
43 | Nast.Reified -> acc
45 method! on_tvarray acc r _ = this#invalid acc r "an array type"
47 method! on_tdarray acc r _ _ = this#invalid acc r "an array type"
49 method! on_tvarray_or_darray acc r _ _ = this#invalid acc r "an array type"
51 method! on_tfun acc r _ = this#invalid acc r "a function type"
53 method! on_typeconst acc is_concrete typeconst =
54 match typeconst.ttc_abstract with
55 | _ when Option.is_some typeconst.ttc_reifiable || is_concrete ->
56 super#on_typeconst acc is_concrete typeconst
57 | _ ->
58 let r = Reason.Rwitness (fst typeconst.ttc_name) in
59 let kind =
60 "an abstract type constant without the __Reifiable attribute"
62 this#invalid acc r kind
64 method! on_taccess acc r (root, ids) =
65 let acc =
66 match acc.reification with
67 | Unresolved -> this#on_type acc root
68 | Resolved -> acc
70 super#on_taccess acc r (root, ids)
72 method! on_tthis acc r =
73 this#invalid acc r "the late static bound this type"
74 end