Skip to content

Commit 4f78685

Browse files
committed
let destructuring grouping fix
1 parent b2df586 commit 4f78685

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ppx_regexp/transformations.ml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,17 @@ let transform_destructuring_let ~mode ~loc pattern_str expr =
305305
in
306306
match List.rev bs with
307307
| [] -> [%expr ()]
308-
| [ (_, _, conv, _) ] -> apply_conv ~loc [%expr Re.Group.get _g 1] conv
309308
| bs_rev ->
310-
let exprs = List.mapi (fun i (_, _, conv, _) -> apply_conv ~loc [%expr Re.Group.get _g [%e eint ~loc (i + 1)]] conv) bs_rev in
311-
pexp_tuple ~loc exprs
309+
let exprs =
310+
List.map
311+
begin
312+
fun (_, iG, conv, _) ->
313+
let group_idx = match iG with None -> 0 | Some i -> i + 1 in
314+
apply_conv ~loc [%expr Re.Group.get _g [%e eint ~loc group_idx]] conv
315+
end
316+
bs_rev
317+
in
318+
(match exprs with [ expr ] -> expr | _ -> pexp_tuple ~loc exprs)
312319
in
313320

314321
let default_rhs = [%expr [%e make_default_rhs ~mode ~target:`Let ~loc []]] in

0 commit comments

Comments
 (0)