Skip to content

Commit 4eed0c7

Browse files
committed
disallow rest spreading on packed modules
1 parent a546914 commit 4eed0c7

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

compiler/frontend/ast_tuple_pattern_flatten.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ let flattern_tuple_pattern_vb (self : Bs_ast_mapper.mapper)
6464
}
6565
:: acc)
6666
| _ -> {pvb_pat; pvb_expr; pvb_loc = vb.pvb_loc; pvb_attributes} :: acc)
67-
| Ppat_record (lid_pats, _, _rest), Pexp_pack {pmod_desc = Pmod_ident id} ->
67+
| Ppat_record (_, _, Some rest), Pexp_pack {pmod_desc = Pmod_ident _} ->
68+
Location.raise_errorf ~loc:rest.ppat_loc
69+
"Record rest patterns are not supported when destructuring modules. Bind \
70+
the module fields explicitly."
71+
| Ppat_record (lid_pats, _, None), Pexp_pack {pmod_desc = Pmod_ident id} ->
6872
Ext_list.map_append lid_pats acc (fun {lid; x = pat} ->
6973
match lid.txt with
7074
| Lident s ->
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/record_rest_module_destructure.res:3:15-34
4+
5+
1 │ module A = Belt.Array
6+
2 │
7+
3 │ let {push, ...arrayMethods as rest} = module(A)
8+
4 │
9+
10+
Record rest patterns are not supported when destructuring modules. Bind the module fields explicitly.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module A = Belt.Array
2+
3+
let {push, ...arrayMethods as rest} = module(A)

0 commit comments

Comments
 (0)