2 * Copyright (c) 2018, 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.
14 module MakeType
= Typing_make_type
15 module SN
= Naming_special_names
17 let rxTraversableType =
21 [MakeType.mixed
Reason.Rnone
]
23 let rxAsyncIteratorType =
27 [MakeType.mixed
Reason.Rnone
]
29 let check_foreach_collection env p ty
=
30 (* do nothing if unsafe_rx is set *)
31 if TypecheckerOptions.unsafe_rx
(Env.get_tcopt env
) then
34 match Env.env_reactivity env
with
35 | r
when not
(any_reactive r
) -> ()
38 let (env
, ty
) = Env.expand_type env ty
in
39 match get_node ty
with
40 | Tunion l
-> List.for_all l ~f
:check
42 (* If it's a dynamic, we have no way of knowing whether or not it's
43 valid. Let it fail at runtime *)
46 (* collection type should be subtype or conditioned to Rx\Traversable *)
49 ( Env.can_subtype env ty
rxTraversableType
50 || Env.can_subtype env ty
rxAsyncIteratorType
51 || Env.condition_type_matches
56 || Env.condition_type_matches
62 Errors.invalid_traversable_in_rx p
;
71 inherit Tast_visitor.handler_base
73 method! at_stmt env x
=
75 | Foreach
(((p
, ty
), _
), _
, _
) -> check_foreach_collection env p ty