Skip to content

Commit e53ab8a

Browse files
committed
Capture pc_loc instead of pc_bar
1 parent b11f460 commit e53ab8a

File tree

14 files changed

+56
-29
lines changed

14 files changed

+56
-29
lines changed

analysis/src/Codemod.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ let transform ~path ~pos ~debug ~typ ~hint =
1919
let cases =
2020
collectPatterns pattern
2121
|> List.map (fun (p : Parsetree.pattern) ->
22-
Ast_helper.Exp.case p (TypeUtils.Codegen.mkFailWithExp ()))
22+
Ast_helper.Exp.case p.ppat_loc p
23+
(TypeUtils.Codegen.mkFailWithExp ()))
2324
in
2425
let result = ref None in
2526
let mkIterator ~pos ~result =

analysis/src/TypeUtils.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ module Codegen = struct
10441044
Some
10451045
(patterns
10461046
|> List.map (fun (pat : Parsetree.pattern) ->
1047-
Ast_helper.Exp.case pat (mkFailWithExp ())))
1047+
Ast_helper.Exp.case pat.ppat_loc pat (mkFailWithExp ())))
10481048
end
10491049

10501050
let getModulePathRelativeToEnv ~debug ~(env : QueryEnv.t) ~envFromItem path =

analysis/src/Xform.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,13 @@ module IfThenElse = struct
105105
let mkMatch ~arg ~pat =
106106
let cases =
107107
[
108-
Ast_helper.Exp.case pat e1;
109-
Ast_helper.Exp.case (Ast_helper.Pat.any ()) e2;
108+
Ast_helper.Exp.case
109+
{
110+
pat.Parsetree.ppat_loc with
111+
Location.loc_end = e1.pexp_loc.loc_end;
112+
}
113+
pat e1;
114+
Ast_helper.Exp.case e2.pexp_loc (Ast_helper.Pat.any ()) e2;
110115
]
111116
in
112117
Ast_helper.Exp.match_ ~loc:e.pexp_loc ~attrs:e.pexp_attributes arg

compiler/frontend/bs_ast_mapper.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,9 @@ let default_mapper =
539539
~attrs:(this.attributes this pld_attributes));
540540
cases = (fun this l -> List.map (this.case this) l);
541541
case =
542-
(fun this {pc_bar; pc_lhs; pc_guard; pc_rhs} ->
542+
(fun this {pc_loc; pc_lhs; pc_guard; pc_rhs} ->
543543
{
544-
pc_bar;
544+
pc_loc = this.location this pc_loc;
545545
pc_lhs = this.pat this pc_lhs;
546546
pc_guard = map_opt (this.expr this) pc_guard;
547547
pc_rhs = this.expr this pc_rhs;

compiler/frontend/bs_builtin_ppx.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,15 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
167167
pexp_desc =
168168
Pexp_match
169169
( pvb_expr,
170-
[{pc_bar = None; pc_lhs = p; pc_guard = None; pc_rhs = body}] );
170+
[
171+
{
172+
pc_loc =
173+
{p.ppat_loc with Location.loc_end = body.pexp_loc.loc_end};
174+
pc_lhs = p;
175+
pc_guard = None;
176+
pc_rhs = body;
177+
};
178+
] );
171179
pexp_attributes = e.pexp_attributes @ pvb_attributes;
172180
})
173181
(* let [@warning "a"] {a;b} = c in body

compiler/ml/ast_helper.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ module Exp = struct
208208
jsx_container_element_closing_tag = e;
209209
}))
210210

211-
let case ?bar lhs ?guard rhs =
212-
{pc_bar = bar; pc_lhs = lhs; pc_guard = guard; pc_rhs = rhs}
211+
let case loc lhs ?guard rhs =
212+
{pc_loc = loc; pc_lhs = lhs; pc_guard = guard; pc_rhs = rhs}
213213

214214
let make_list_expression loc seq ext_opt =
215215
let rec handle_seq = function

compiler/ml/ast_helper.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ module Exp : sig
231231
Parsetree.jsx_closing_container_tag option ->
232232
expression
233233

234-
val case :
235-
?bar:Lexing.position -> pattern -> ?guard:expression -> expression -> case
234+
val case : Location.t -> pattern -> ?guard:expression -> expression -> case
236235
val await : ?loc:loc -> ?attrs:attrs -> expression -> expression
237236

238237
val make_list_expression :

compiler/ml/ast_mapper.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ let default_mapper =
488488
~attrs:(this.attributes this pld_attributes));
489489
cases = (fun this l -> List.map (this.case this) l);
490490
case =
491-
(fun this {pc_bar; pc_lhs; pc_guard; pc_rhs} ->
491+
(fun this {pc_loc; pc_lhs; pc_guard; pc_rhs} ->
492492
{
493-
pc_bar;
493+
pc_loc = this.location this pc_loc;
494494
pc_lhs = this.pat this pc_lhs;
495495
pc_guard = map_opt (this.expr this) pc_guard;
496496
pc_rhs = this.expr this pc_rhs;

compiler/ml/ast_mapper_from0.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,9 @@ let default_mapper =
665665
case =
666666
(fun this {pc_lhs; pc_guard; pc_rhs} ->
667667
{
668-
pc_bar = None;
668+
pc_loc =
669+
this.location this
670+
{pc_lhs.ppat_loc with Location.loc_end = pc_rhs.pexp_loc.loc_end};
669671
pc_lhs = this.pat this pc_lhs;
670672
pc_guard = map_opt (this.expr this) pc_guard;
671673
pc_rhs = this.expr this pc_rhs;

compiler/ml/parsetree.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ and jsx_closing_container_tag = {
381381

382382
and case = {
383383
(* (P -> E) or (P when E0 -> E) *)
384-
pc_bar: Lexing.position option;
384+
pc_loc: Location.t;
385385
pc_lhs: pattern;
386386
pc_guard: expression option;
387387
pc_rhs: expression;

0 commit comments

Comments
 (0)