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.
15 module MakeType
= Typing_make_type
17 let rxTraversableType =
18 MakeType.class_type
Reason.none
Naming_special_names.Rx.cTraversable
[(Reason.Rnone
, Tany
)]
20 let rxAsyncIteratorType =
21 MakeType.class_type
Reason.none
Naming_special_names.Rx.cAsyncIterator
[(Reason.Rnone
, Tany
)]
23 let check_foreach_collection env p ty
=
24 (* do nothing if unsafe_rx is set *)
25 if TypecheckerOptions.unsafe_rx
(Env.get_tcopt env
) then () else
26 match Env.env_reactivity env
with | Nonreactive
| Local _
-> () | _
->
28 let env, ty
= Env.expand_type
env ty
in
30 | _
, Tunion l
-> List.for_all l ~f
:check
32 (* collection type should be subtype or conditioned to Rx\Traversable *)
33 if not
(Env.can_subtype
env ty
rxTraversableType ||
34 Env.can_subtype
env ty
rxAsyncIteratorType ||
35 Env.condition_type_matches ~is_self
:false env ty
rxTraversableType ||
36 Env.condition_type_matches ~is_self
:false env ty
rxAsyncIteratorType)
38 Errors.invalid_traversable_in_rx p
;
45 inherit Tast_visitor.handler_base
47 method! at_stmt
env x
=
49 | Foreach
(((p
, ty
), _
), _
, _
) -> check_foreach_collection env p ty