Skip to content

Commit c3bee7b

Browse files
committed
eq, ord, show: also hygienically invoke functions from other modules.
Fixes #57.
1 parent 320bbbc commit c3bee7b

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

src_plugins/ppx_deriving_eq.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ and expr_of_typ quoter typ =
8484
[%expr fun (lazy x) (lazy y) -> [%e expr_of_typ typ] x y]
8585
| _, { ptyp_desc = Ptyp_constr ({ txt = lid }, args) } ->
8686
let equal_fn = Exp.ident (mknoloc (Ppx_deriving.mangle_lid (`Prefix "equal") lid)) in
87-
let fwd = app equal_fn (List.map expr_of_typ args) in
87+
let fwd = app (Ppx_deriving.quote quoter equal_fn) (List.map expr_of_typ args) in
8888
(* eta-expansion is necessary for recursive groups *)
8989
[%expr fun x -> [%e fwd] x]
9090
| _ -> assert false

src_plugins/ppx_deriving_ord.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ and expr_of_typ quoter typ =
9090
[%expr fun (lazy x) (lazy y) -> [%e expr_of_typ typ] x y]
9191
| _, { ptyp_desc = Ptyp_constr ({ txt = lid }, args) } ->
9292
let compare_fn = Exp.ident (mknoloc (Ppx_deriving.mangle_lid (`Prefix "compare") lid)) in
93-
let fwd = app compare_fn (List.map expr_of_typ args) in
93+
let fwd = app (Ppx_deriving.quote quoter compare_fn) (List.map expr_of_typ args) in
9494
(* eta-expansion is necessary for recursive groups *)
9595
[%expr fun x -> [%e fwd] x]
9696
| _ -> assert false

src_plugins/ppx_deriving_show.ml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,15 @@ let rec expr_of_typ quoter typ =
115115
else Format.pp_print_string fmt "<not evaluated>"]
116116
| _, { ptyp_desc = Ptyp_constr ({ txt = lid }, args) } ->
117117
let args_pp = List.map (fun typ -> [%expr fun fmt -> [%e expr_of_typ typ]]) args in
118-
begin match attr_polyprinter typ.ptyp_attributes with
119-
| Some printer ->
120-
let printer =
118+
let printer =
119+
match attr_polyprinter typ.ptyp_attributes with
120+
| Some printer ->
121121
[%expr (let fprintf = Format.fprintf in [%e printer]) [@ocaml.warning "-26"]]
122-
in
123-
app (Ppx_deriving.quote quoter printer)
124-
(args_pp @ [[%expr fmt]])
125-
| None ->
126-
app (Exp.ident (mknoloc (Ppx_deriving.mangle_lid (`Prefix "pp") lid)))
127-
(args_pp @ [[%expr fmt]])
128-
end
122+
| None ->
123+
Exp.ident (mknoloc (Ppx_deriving.mangle_lid (`Prefix "pp") lid))
124+
in
125+
app (Ppx_deriving.quote quoter printer)
126+
(args_pp @ [[%expr fmt]])
129127
| _ -> assert false
130128
end
131129
| { ptyp_desc = Ptyp_tuple typs } ->

src_test/test_deriving_eq.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ let test_poly_app ctxt =
109109
assert_equal ~printer true (equal_poly_app 1.0 1.0);
110110
assert_equal ~printer false (equal_poly_app 1.0 2.0)
111111

112+
module List = struct
113+
type 'a t = [`Cons of 'a | `Nil]
114+
[@@deriving eq]
115+
end
116+
type 'a std_clash = 'a List.t option
117+
[@@deriving eq]
118+
112119
let suite = "Test deriving(eq)" >::: [
113120
"test_simple" >:: test_simple;
114121
"test_custom" >:: test_custom;

src_test/test_deriving_ord.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ let test_poly_app ctxt =
123123
assert_equal ~printer 0 (compare_poly_app 1.0 1.0);
124124
assert_equal ~printer (-1) (compare_poly_app 1.0 2.0)
125125

126+
module List = struct
127+
type 'a t = [`Cons of 'a | `Nil]
128+
[@@deriving ord]
129+
end
130+
type 'a std_clash = 'a List.t option
131+
[@@deriving ord]
132+
126133
module Warnings = struct
127134
module W4 = struct
128135
[@@@ocaml.warning "@4"]

src_test/test_deriving_show.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ and 'a poly_abs = 'a
164164
let test_poly_app ctxt =
165165
assert_equal ~printer "1." (show_poly_app 1.0)
166166

167+
module List = struct
168+
type 'a t = [`Cons of 'a | `Nil]
169+
[@@deriving show]
170+
end
171+
type 'a std_clash = 'a List.t option
172+
[@@deriving show]
173+
167174
let suite = "Test deriving(show)" >::: [
168175
"test_alias" >:: test_alias;
169176
"test_variant" >:: test_variant;

0 commit comments

Comments
 (0)