From de5b60bc5ca5507b032f93ef8f162a9962fdd9f7 Mon Sep 17 00:00:00 2001 From: Boning Date: Fri, 19 Jan 2024 01:23:38 +0000 Subject: [PATCH] Fix validation multiple derivers --- dune-project | 1 + ppx_make.opam | 3 ++- src/utils.ml | 12 ++++++++++-- test/dune | 4 ++-- test/misc_types.ml | 2 +- test/test_make.ml | 5 +++++ 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/dune-project b/dune-project index 957e140..3612e89 100644 --- a/dune-project +++ b/dune-project @@ -17,4 +17,5 @@ (depends (ppxlib (>= 0.10.0)) (ounit2 :with-test) + (ppx_show :with-test) (bisect_ppx :with-test))) diff --git a/ppx_make.opam b/ppx_make.opam index b601c08..0ad5f87 100644 --- a/ppx_make.opam +++ b/ppx_make.opam @@ -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 "] @@ -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} ] diff --git a/src/utils.ml b/src/utils.ml index 47e2ec0..2fd0292 100644 --- a/src/utils.ml +++ b/src/utils.ml @@ -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 diff --git a/test/dune b/test/dune index 379e33f..aefc310 100644 --- a/test/dune +++ b/test/dune @@ -1,5 +1,5 @@ (test (name test_make) (preprocess - (pps ppx_make)) - (libraries ounit2)) + (pps ppx_make ppx_show)) + (libraries ounit2 ppx_show.runtime)) diff --git a/test/misc_types.ml b/test/misc_types.ml index 1c47baa..919ea9f 100644 --- a/test/misc_types.ml +++ b/test/misc_types.ml @@ -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 diff --git a/test/test_make.ml b/test/test_make.ml index 8d5cdff..dc8fb97 100644 --- a/test/test_make.ml +++ b/test/test_make.ml @@ -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 @@ -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; ])