Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error using when eq/ord with mutual-rec type #20

Merged
merged 1 commit into from
Jan 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix error using when eq/ord with mutual-rec type
 - Add tests for mutual recursive type to eq and ord plugin's test
 - Fix code generation for list type eq and ord plugin to avoid the
   error of 'let rec' restriction (This kind of expression is not
   allowed as right-hand side of `let rec')
  • Loading branch information
runoshun committed Jan 11, 2015
commit f1861b8df20c850212798c3442b02be77afaba24
2 changes: 1 addition & 1 deletion src_plugins/ppx_deriving_eq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ and expr_of_typ typ =
| [], [] -> true
| a :: x, b :: y -> [%e expr_of_typ typ] a b && loop x y
| _ -> false
in loop]
in (fun x y -> loop x y)]
| [%type: [%t? typ] array] ->
[%expr fun x y ->
let rec loop i =
Expand Down
2 changes: 1 addition & 1 deletion src_plugins/ppx_deriving_ord.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ and expr_of_typ typ =
| _, [] -> 1
| a :: x, b :: y ->
[%e compare_reduce [%expr loop x y] [%expr [%e expr_of_typ typ] a b]]
in loop]
in (fun x y -> loop x y)]
| [%type: [%t? typ] array] ->
[%expr fun x y ->
let rec loop i =
Expand Down
15 changes: 15 additions & 0 deletions src_test/test_deriving_eq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,23 @@ type 'a pt = { v : 'a } [@@deriving eq]
let test_placeholder ctxt =
assert_equal ~printer true ([%eq: _] 1 2)


type mrec_variant =
| MrecFoo of string
| MrecBar of int

and mrec_variant_list = mrec_variant list [@@deriving eq]

let test_mrec ctxt =
assert_equal ~printer true (equal_mrec_variant_list [MrecFoo "foo"; MrecBar 1]
[MrecFoo "foo"; MrecBar 1]);
assert_equal ~printer false (equal_mrec_variant_list [MrecFoo "foo"; MrecBar 1]
[MrecFoo "bar"; MrecBar 1])

let suite = "Test deriving(eq)" >::: [
"test_simple" >:: test_simple;
"test_custom" >:: test_custom;
"test_placeholder" >:: test_placeholder;
"test_mrec" >:: test_mrec;
]

17 changes: 17 additions & 0 deletions src_test/test_deriving_ord.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,27 @@ type 'a pt = { v : 'a } [@@deriving ord]
let test_placeholder ctxt =
assert_equal ~printer 0 ([%ord: _] 1 2)

type mrec_variant =
| MrecFoo of string
| MrecBar of int

and mrec_variant_list = mrec_variant list
[@@deriving ord]

let test_mrec ctxt =
assert_equal ~printer (0) (compare_mrec_variant_list [MrecFoo "foo"; MrecBar 1;]
[MrecFoo "foo"; MrecBar 1;]);
assert_equal ~printer (-1) (compare_mrec_variant_list [MrecFoo "foo"; MrecBar 1;]
[MrecFoo "foo"; MrecBar 2;]);
assert_equal ~printer (1) (compare_mrec_variant_list [MrecFoo "foo"; MrecBar 2;]
[MrecFoo "foo"; MrecBar 1;])

let suite = "Test deriving(ord)" >::: [
"test_simple" >:: test_simple;
"test_variant" >:: test_variant;
"test_complex" >:: test_complex;
"test_custom" >:: test_custom;
"test_placeholder" >:: test_placeholder;
"test_mrec" >:: test_mrec;
]