Skip to content

Commit

Permalink
Fix validation multiple derivers
Browse files Browse the repository at this point in the history
  • Loading branch information
bn-d committed Jan 19, 2024
1 parent 9a6ac74 commit de5b60b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
(depends
(ppxlib (>= 0.10.0))
(ounit2 :with-test)
(ppx_show :with-test)
(bisect_ppx :with-test)))
3 changes: 2 additions & 1 deletion ppx_make.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.3.3"
version: "0.3.4"
synopsis: "[@@deriving make]"
description: "[@@deriving] plugin to generate make functions"
maintainer: ["Boning <me@boni.ng>"]
Expand All @@ -13,6 +13,7 @@ depends: [
"dune" {>= "2.7"}
"ppxlib" {>= "0.10.0"}
"ounit2" {with-test}
"ppx_show" {with-test}
"bisect_ppx" {with-test}
"odoc" {with-doc}
]
Expand Down
12 changes: 10 additions & 2 deletions src/utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ let unsupported_error str { txt; loc } =
Location.raise_errorf ~loc "%s %s cannot be derived" str txt

let has_make_attr ({ ptype_attributes; _ } : type_declaration) =
let is_make = function [%stri make] -> true | _ -> false in
let is_make = function [%expr make] -> true | _ -> false in
List.exists
(fun (attr : attribute) ->
(attr.attr_name.txt = "deriving" || attr.attr_name.txt = "deriving_inline")
&&
match attr.attr_payload with
| PStr items -> List.exists is_make items
| PStr [ { pstr_desc = Pstr_eval ([%expr make], _); _ } ] -> true
| PStr
[
{
pstr_desc = Pstr_eval ({ pexp_desc = Pexp_tuple exprs; _ }, _);
_;
};
] ->
List.exists is_make exprs
| _ -> false)
ptype_attributes

Expand Down
4 changes: 2 additions & 2 deletions test/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(test
(name test_make)
(preprocess
(pps ppx_make))
(libraries ounit2))
(pps ppx_make ppx_show))
(libraries ounit2 ppx_show.runtime))
2 changes: 1 addition & 1 deletion test/misc_types.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(* https://github.com/bn-d/ppx_make/issues/12 *)
type a = { i : int } [@@deriving make]
type a = { i : int } [@@deriving make, show]
and b = int
5 changes: 5 additions & 0 deletions test/test_make.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
let test_multiple_type_decl _ =
let open Misc_types in
OUnit.assert_equal { i = 1 } @@ make_a ~i:1 ()

let _ =
let open OUnit2 in
run_test_tt_main
Expand All @@ -8,4 +12,5 @@ let _ =
Test_make_record.suite;
Test_make_tuple.suite;
Test_make_variant.suite;
"test_multiple_type_decl" >:: test_multiple_type_decl;
])

0 comments on commit de5b60b

Please sign in to comment.