Avoid using decl_class_type wherever possible
[hiphop-php.git] / hphp / hack / src / typing / tast_check / xhp_check.ml
blob3b63393bfc8d5a44a3c135b500e393060de83f05
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 Core_kernel
11 open Tast
12 open Typing_defs
14 module Env = Tast_env
16 let check_xhp_children env pos ty =
17 let _, ty = Env.expand_type env ty in
18 let _, ty = Env.fold_unresolved env ty in
19 let tys = match ty with
20 | _, Tunresolved ts -> ts
21 | _ -> [ty] in
22 if not @@ List.for_all ~f:(Env.is_xhp_child env pos) tys
23 then
24 let ty_str = Env.print_error_ty env ty in
25 let msgl = Reason.to_string ("This is "^ty_str) (fst ty) in
26 Errors.illegal_xhp_child pos msgl
28 let handler = object
29 inherit Tast_visitor.handler_base
31 method! at_expr env = function
32 | _, Xml (_, _, tel) ->
33 List.iter tel ~f:(fun ((pos, ty), _) -> check_xhp_children env pos ty)
34 | _ -> ()
35 end