File tree 3 files changed +30
-2
lines changed
3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change
1
+ unreleased
2
+ ----------
3
+
4
+ * Fix ordering of derived ` make ` 's arguments
5
+ #285
6
+ (@NathanReb )
7
+
1
8
6.0.1 (17/04/2024)
2
9
------------------
3
10
Original file line number Diff line number Diff line change @@ -97,7 +97,9 @@ let str_of_record_type ~quoter ~loc labels =
97
97
| None ->
98
98
record fields
99
99
in
100
- List. fold_left (add_str_label_arg ~quoter ~loc ) fn labels
100
+ (* The labels list must be reversed here so that the arguments are in the
101
+ same order as the record fields. *)
102
+ List. fold_left (add_str_label_arg ~quoter ~loc ) fn (List. rev labels)
101
103
102
104
let str_of_type ({ ptype_loc = loc } as type_decl ) =
103
105
let quoter = Ppx_deriving. create_quoter () in
@@ -156,7 +158,9 @@ let sig_of_record_type ~loc ~typ labels =
156
158
| None when has_option -> Typ. arrow Label. nolabel (tconstr " unit" [] ) typ
157
159
| None -> typ
158
160
in
159
- List. fold_left add_sig_label_arg typ labels
161
+ (* The labels list must be reversed here so that the arguments are in the
162
+ same order as the record fields. *)
163
+ List. fold_left add_sig_label_arg typ (List. rev labels)
160
164
161
165
let sig_of_type ({ ptype_loc = loc } as type_decl ) =
162
166
let typ = Ppx_deriving. core_type_of_type_decl type_decl in
Original file line number Diff line number Diff line change @@ -64,6 +64,23 @@ end = struct
64
64
[@@ deriving show]
65
65
end
66
66
67
+ (* This module is here to test that the ordering of the arguments
68
+ match the order of the record fields declarations. *)
69
+ module M2 : sig
70
+ type t =
71
+ { first : int
72
+ ; second : int
73
+ }
74
+
75
+ val make : first : int -> second : int -> t
76
+ end = struct
77
+ type t =
78
+ { first : int
79
+ ; second : int
80
+ }
81
+ [@@ deriving make ]
82
+ end
83
+
67
84
let test_no_main ctxt =
68
85
assert_equal ~printer: M. show_a
69
86
{ M. a1 = None ; a2 = [] ; a3 = 42 ; a4s = 2 , [] ; a5 = 1 }
You can’t perform that action at this time.
0 commit comments