From 2812d3be6e90d1d55aca5c68a9c58d14c6c4672a Mon Sep 17 00:00:00 2001 From: Mathieu Barbin Date: Tue, 16 Jul 2024 10:36:35 +0200 Subject: [PATCH] Various fixes and improvements - Share the [Forcable_bool.Arg] logic. - Fixes some typos. Signed-off-by: Mathieu Barbin --- src/deriving.ml | 20 ++------------------ src/options.ml | 11 +++++++++++ test/deriving_warning/run.t | 6 +++--- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/deriving.ml b/src/deriving.ml index 7d5ae8ae..7fcaf40c 100644 --- a/src/deriving.ml +++ b/src/deriving.ml @@ -63,15 +63,7 @@ let allow_unused_code_warnings = ref Options.default_allow_unused_code_warnings let () = Driver.add_arg "-unused-code-warnings" - (Symbol - ( [ "true"; "false"; "force" ], - fun flag -> - allow_unused_code_warnings := - match flag with - | "true" -> True - | "false" -> False - | "force" -> Force - | _ -> assert false )) + (Options.Forcable_bool.arg allow_unused_code_warnings) ~doc:" Allow ppx derivers to enable unused code warnings (default: false)" let allow_unused_code_warnings ~ppx_allows_unused_code_warnings = @@ -84,15 +76,7 @@ let allow_unused_type_warnings = ref Options.default_allow_unused_type_warnings let () = Driver.add_arg "-unused-type-warnings" - (Symbol - ( [ "true"; "false"; "force" ], - fun flag -> - allow_unused_type_warnings := - match flag with - | "true" -> True - | "false" -> False - | "force" -> Force - | _ -> assert false )) + (Options.Forcable_bool.arg allow_unused_type_warnings) ~doc: " Allow unused type warnings for types with [@@deriving ...] (default: \ false)" diff --git a/src/options.ml b/src/options.ml index af37a3e6..2ec6eef9 100644 --- a/src/options.ml +++ b/src/options.ml @@ -1,5 +1,16 @@ module Forcable_bool = struct type t = True | False | Force + + let arg value = + Arg.Symbol + ( [ "true"; "false"; "force" ], + fun flag -> + value := + match flag with + | "true" -> True + | "false" -> False + | "force" -> Force + | _ -> assert false ) end let default_allow_unused_code_warnings : Forcable_bool.t = False diff --git a/test/deriving_warning/run.t b/test/deriving_warning/run.t index e381f25e..a6a26893 100644 --- a/test/deriving_warning/run.t +++ b/test/deriving_warning/run.t @@ -296,7 +296,7 @@ Same goes for .mli: -------------------------------------------------------------------------------- Whenever a set of types has a [@@deriving ...] attached, ppxlib's driver always -generate structure items meant to disable unused type warnings (warning 34) for +generates structure items meant to disable unused type warnings (warning 34) for any of those types. Let's consider the following piece of OCaml code: @@ -328,8 +328,8 @@ We can see that the driver generated two `let _ = fun (_ : ...`, one for each ty in the set. As we mentioned before, the driver flag (`-unused-code-warnings`) allows the -user to disable all warnings . In addition to this more general flag, we have a -flag that disable only this part, and allows unused type warnings to be reported +user to disable all warnings. In addition to this more general flag, we have a +flag that disables only this part, and allows unused type warnings to be reported properly. Passing that flag to the driver should remove the two previously mentioned items, without affecting the rest of the generated anti-warning items: