Skip to content

Commit

Permalink
[flow] Replace RCustom "providers" with an identifier description
Browse files Browse the repository at this point in the history
Summary:
We should never show providers as the reason to the user. Instead, in all the call sites, we have access to the identifier name, so we should use that as reason description instead.

In these cases, it doesn't quite matter, since the reason is only accessible from typed ast, but it's still better than RCustom.

Changelog: [internal]

Reviewed By: gkz

Differential Revision: D56714487

fbshipit-source-id: 5496073588df5c08dd21d4d20b7061a58c563abc
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Apr 29, 2024
1 parent a48bf8f commit d07fbab
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/typing/destructuring.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/typing/statement.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/typing/type_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 *)
Expand Down
2 changes: 1 addition & 1 deletion src/typing/type_env.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d07fbab

Please sign in to comment.