Skip to content

Commit 139324f

Browse files
committed
Improve error when using '@deriving(accessors)` on a variant with a record arg
1 parent 5d5440c commit 139324f

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#### :bug: Bug Fix
1616

1717
- Fix variance setting for builtin `dict` type. Fixes issues around inference. https://github.com/rescript-lang/rescript-compiler/pull/6707
18+
- Improve error when using '@deriving(accessors)' on a variant with record arguments
1819

1920
# 11.1.0-rc.6
2021

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/DerivingAccessorsRecordParam.res:2:10-25
4+
5+
1 │ @deriving(accessors)
6+
2 │ type t = Struct({a: int})
7+
3 │
8+
9+
@deriving(accessors) from a variant record argument is unsupported. Either define the record type separately from the variant type or use a positional argument.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@deriving(accessors)
2+
type t = Struct({a: int})

jscomp/frontend/ast_derive_projector.ml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,20 @@ let init () =
5555
{
5656
pcd_name = {loc; txt = con_name};
5757
pcd_args;
58-
pcd_loc = _;
58+
pcd_loc;
5959
pcd_res;
6060
}
6161
->
6262
(* TODO: add type annotations *)
6363
let pcd_args =
6464
match pcd_args with
6565
| Pcstr_tuple pcd_args -> pcd_args
66-
| Pcstr_record _ -> assert false
66+
| Pcstr_record _ ->
67+
Location.raise_errorf ~loc:pcd_loc
68+
"@deriving(accessors) from a variant record argument \
69+
is unsupported. Either define the record type \
70+
separately from the variant type or use a \
71+
positional argument."
6772
in
6873
let little_con_name =
6974
Ext_string.uncapitalize_ascii con_name
@@ -146,14 +151,19 @@ let init () =
146151
{
147152
pcd_name = {loc; txt = con_name};
148153
pcd_args;
149-
pcd_loc = _;
154+
pcd_loc;
150155
pcd_res;
151156
}
152157
->
153158
let pcd_args =
154159
match pcd_args with
155160
| Pcstr_tuple pcd_args -> pcd_args
156-
| Pcstr_record _ -> assert false
161+
| Pcstr_record _ ->
162+
Location.raise_errorf ~loc:pcd_loc
163+
"@deriving(accessors) from a variant record argument \
164+
is unsupported. Either define the record type \
165+
separately from the variant type or use a \
166+
positional argument."
157167
in
158168
let arity = pcd_args |> List.length in
159169
let annotate_type =

0 commit comments

Comments
 (0)