Skip to content

Commit

Permalink
Various fixes and improvements
Browse files Browse the repository at this point in the history
- Share the [Forcable_bool.Arg] logic.
- Fixes some typos.

Signed-off-by: Mathieu Barbin <[email protected]>
  • Loading branch information
mbarbin committed Jul 16, 2024
1 parent a8e4f96 commit a4710df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
20 changes: 2 additions & 18 deletions src/deriving.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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)"
Expand Down
11 changes: 11 additions & 0 deletions src/options.ml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/deriving_warning/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:

Expand Down

0 comments on commit a4710df

Please sign in to comment.