File tree Expand file tree Collapse file tree 4 files changed +27
-4
lines changed Expand file tree Collapse file tree 4 files changed +27
-4
lines changed Original file line number Diff line number Diff line change 1212
1313# 11.1.0-rc.8 (Unreleased)
1414
15+ #### :bug : Bug Fix
16+
17+ - Improve error when using '@deriving (accessors)' on a variant with record arguments. https://github.com/rescript-lang/rescript-compiler/pull/6712
18+
1519# 11.1.0-rc.7
1620
1721#### :bug : Bug Fix
Original file line number Diff line number Diff line change 1+
2+ [1;31mWe've found a bug for you![0m
3+ [36m/.../fixtures/DerivingAccessorsRecordParam.res[0m:[2m2:10-25[0m
4+
5+ 1 [2m│[0m @deriving(accessors)
6+ [1;31m2[0m [2m│[0m type t = [1;31mStruct({a: int})[0m
7+ 3 [2m│[0m
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.
Original file line number Diff line number Diff line change 1+ @deriving (accessors )
2+ type t = Struct ({a : int })
Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ let invalid_config (config : Parsetree.expression) =
44 Location. raise_errorf ~loc: config.pexp_loc
55 " such configuration is not supported"
66
7+ let raise_unsupported_vaiant_record_arg loc =
8+ Location. raise_errorf ~loc
9+ " @deriving(accessors) from a variant record argument is unsupported. \
10+ Either define the record type separately from the variant type or use a \
11+ positional argument."
12+
713type tdcls = Parsetree .type_declaration list
814
915let derivingName = " accessors"
@@ -55,15 +61,16 @@ let init () =
5561 {
5662 pcd_name = {loc; txt = con_name } ;
5763 pcd_args;
58- pcd_loc = _ ;
64+ pcd_loc;
5965 pcd_res;
6066 }
6167 ->
6268 (* TODO: add type annotations *)
6369 let pcd_args =
6470 match pcd_args with
6571 | Pcstr_tuple pcd_args -> pcd_args
66- | Pcstr_record _ -> assert false
72+ | Pcstr_record _ ->
73+ raise_unsupported_vaiant_record_arg pcd_loc
6774 in
6875 let little_con_name =
6976 Ext_string. uncapitalize_ascii con_name
@@ -146,14 +153,15 @@ let init () =
146153 {
147154 pcd_name = {loc; txt = con_name } ;
148155 pcd_args;
149- pcd_loc = _ ;
156+ pcd_loc;
150157 pcd_res;
151158 }
152159 ->
153160 let pcd_args =
154161 match pcd_args with
155162 | Pcstr_tuple pcd_args -> pcd_args
156- | Pcstr_record _ -> assert false
163+ | Pcstr_record _ ->
164+ raise_unsupported_vaiant_record_arg pcd_loc
157165 in
158166 let arity = pcd_args |> List. length in
159167 let annotate_type =
You can’t perform that action at this time.
0 commit comments