diff --git a/src/typing/destructuring.ml b/src/typing/destructuring.ml index a0758d0061b..814ce022d98 100644 --- a/src/typing/destructuring.ml +++ b/src/typing/destructuring.ml @@ -307,7 +307,7 @@ module Make (Statement : Statement_sig.S) : Destructuring_sig.S = struct let f ~use_op ~name_loc name _default t = (* TODO destructuring+defaults unsupported in assignment expressions *) ignore Type_env.(set_var cx ~use_op name t name_loc); - Type_env.constraining_type ~default:t cx name_loc + Type_env.constraining_type ~default:t cx name name_loc in pattern cx ~f acc end diff --git a/src/typing/statement.ml b/src/typing/statement.ml index f8181a44a84..cc9260beac1 100644 --- a/src/typing/statement.ml +++ b/src/typing/statement.ml @@ -2407,7 +2407,7 @@ module Make init_var cx ~use_op init_t id_loc | None -> () end; - let ast_t = Type_env.constraining_type ~default:annot_t cx id_loc in + let ast_t = Type_env.constraining_type ~default:annot_t cx name id_loc in ( (ploc, ast_t), Ast.Pattern.Identifier { @@ -2458,6 +2458,7 @@ module Make Type_env.constraining_type ~default:(Type_env.get_var_declared_type cx (OrdinaryName name) name_loc) cx + name name_loc ) in diff --git a/src/typing/type_env.ml b/src/typing/type_env.ml index 7b1d4fef0a0..27eee43455a 100644 --- a/src/typing/type_env.ml +++ b/src/typing/type_env.ml @@ -703,7 +703,7 @@ let get_var_declared_type ?(lookup_mode = ForValue) ?(is_declared_function = fal let env = Context.environment cx in provider_type_for_def_loc cx env ~intersect:is_declared_function loc -let constraining_type ~default cx loc = +let constraining_type ~default cx name loc = let { Loc_env.var_info; _ } = Context.environment cx in match EnvMap.find_opt_ordinary loc var_info.Env_api.env_entries with | Some Env_api.NonAssigningWrite -> default @@ -718,7 +718,8 @@ let constraining_type ~default cx loc = | Some [] -> default | Some [t] -> t - | Some (t1 :: t2 :: ts) -> UnionT (mk_reason (RCustom "providers") loc, UnionRep.make t1 t2 ts)) + | Some (t1 :: t2 :: ts) -> + UnionT (mk_reason (RIdentifier (OrdinaryName name)) loc, UnionRep.make t1 t2 ts)) (*************) (* Writing *) diff --git a/src/typing/type_env.mli b/src/typing/type_env.mli index 80660476ced..57915830a67 100644 --- a/src/typing/type_env.mli +++ b/src/typing/type_env.mli @@ -106,7 +106,7 @@ val get_var_declared_type : ALoc.t -> Type.t -val constraining_type : default:Type.t -> Context.t -> ALoc.t -> Type.t +val constraining_type : default:Type.t -> Context.t -> string -> ALoc.t -> Type.t val read_declared_type : Context.t -> Reason.t -> ALoc.t -> Type.t