Skip to content

Commit 358f62e

Browse files
nmotefacebook-github-bot
authored andcommitted
Include location with object type join operator
Reviewed By: samwgoldman Differential Revision: D10223242 fbshipit-source-id: 134d0c50e8a59b5ad52f76af19f602841f7f0433
1 parent 77a0244 commit 358f62e

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/typing/debug_js.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,7 @@ and dump_use_t_ (depth, tvars) cx t =
19471947

19481948
let object_kit =
19491949
let open Object in
1950-
let join = function And -> "And" | Or -> "Or" in
1950+
let join (_loc, op) = match op with And -> "And" | Or -> "Or" in
19511951
let resolved xs =
19521952
spf "[%s]" (String.concat "; " (List.map slice (Nel.to_list xs)))
19531953
in

src/typing/flow_js.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11759,8 +11759,8 @@ and object_kit =
1175911759
match todo with
1176011760
| [] ->
1176111761
let x = match join with
11762-
| Or -> Nel.cons x done_rev |> Nel.concat
11763-
| And -> merge (intersect2_with_reason reason) x done_rev
11762+
| _, Or -> Nel.cons x done_rev |> Nel.concat
11763+
| _, And -> merge (intersect2_with_reason reason) x done_rev
1176411764
in
1176511765
next tool cx trace use_op reason tout x
1176611766
| t::todo ->
@@ -11816,14 +11816,16 @@ and object_kit =
1181611816
rec_flow cx trace (i, GetStaticsT (r, t));
1181711817
rec_flow cx trace (t, ObjKitT (use_op, reason, Resolve resolve_tool, tool, tout))
1181811818
(* Resolve each member of a union. *)
11819-
| DefT (_, UnionT rep) ->
11819+
| DefT (union_reason, UnionT rep) ->
11820+
let union_loc = aloc_of_reason union_reason in
1182011821
let t, todo = UnionRep.members_nel rep in
11821-
let resolve_tool = Resolve (List0 (todo, Or)) in
11822+
let resolve_tool = Resolve (List0 (todo, (union_loc, Or))) in
1182211823
rec_flow cx trace (t, ObjKitT (use_op, reason, resolve_tool, tool, tout))
1182311824
(* Resolve each member of an intersection. *)
11824-
| DefT (_, IntersectionT rep) ->
11825+
| DefT (intersection_reason, IntersectionT rep) ->
11826+
let intersection_loc = aloc_of_reason intersection_reason in
1182511827
let t, todo = InterRep.members_nel rep in
11826-
let resolve_tool = Resolve (List0 (todo, And)) in
11828+
let resolve_tool = Resolve (List0 (todo, (intersection_loc, And))) in
1182711829
rec_flow cx trace (t, ObjKitT (use_op, reason, resolve_tool, tool, tout))
1182811830
(* Mirroring Object.assign() and {...null} semantics, treat null/void as
1182911831
* empty objects. *)

src/typing/type.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,9 @@ and Object : sig
19191919
| List0 of TypeTerm.t Nel.t * join
19201920
| List of TypeTerm.t list * resolved Nel.t * join
19211921

1922-
and join = And | Or
1922+
and join' = And | Or
1923+
(* This location is that of the entire intersection/union, not just the location of the &/| symbol *)
1924+
and join = ALoc.t * join'
19231925

19241926
(* A union type resolves to a resolved spread with more than one element *)
19251927
and resolved = slice Nel.t

0 commit comments

Comments
 (0)