I'm trying to use warning decorators ([@*ocaml.warning]
) to locally remove a warning about a specific unused function, but I can't find the right syntax (if there is one). I'm using OCaml 4.02.1.
In the code below, I have the dbg
function which is not exported and never used, but for which I'd like to silence warning 32 (unused value dbg
).
I want to keep warnings activated elsewhere in the code, to avoid accidental mistakes.
I tried putting all kinds of decorators around the function, but the warning still appears:
A.mli:
val f : unit -> unit
A.ml:
let f () = ()
[@@ocaml.warning "-32"]
let dbg () = () [@ocaml.warning "-32"]
[@@ocaml.warning "-32"]
let bla () = ()
ocamlc -w +a a.mli a.ml
results in:
File "a.ml", line 4, characters 4-7:
Warning 32: unused value dbg.
File "a.ml", line 7, characters 4-7:
Warning 32: unused value bla.
Note that adding [@@@ocaml.warning "-32"]
before let dbg
works (it removes the warning), but then I have to add [@@@ocaml.warning "+32"]
afterwards to re-enable it, which is not ideal, since it enables warnings even when they were not present in the first place.
For instance, if I then compiled with ocamlc a.mli a.ml
, this would add an unwanted warning.
Is there a way to locally disable warning 32?
I believe there is no way to stop individual warning 32 in OCaml 4.02.3.
I had the same trouble at trying to suppress a warning (mine was 39) of one specific toplevel let
. The ticket is http://caml.inria.fr/mantis/view.php?id=6677 and http://caml.inria.fr/mantis/view.php?id=6586.
What you can do so far is to declare such variables with _
prefix:
let _dbg () = ()
since variables start with _
is the out of the scope of warning 32. The downside is that there is no tool available to warn if such _
prefixed value is actually used in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With