I'm trying to use some ppx extensions, and I just found out that OCaml emits no warning for unused/invalid attributes. E.g., if I write something like:
let[@blaa] () = ()
Even with -w +A
, OCaml will not say anything about the fact that @blaa
is never used, and possibly mistyped.
This is especially frustrating when trying to use a ppx rewriter and mistyping a given attribute (e.g. @blaa
instead of @bla
), and having no way to find out about it. Or when a given ppx rewriter has never been enabled at all, and all attributes are just being silently ignored.
Is there a way to enable warnings for such situations?
Note: I tried it with both 4.03.0 and 4.04.0, and in both cases didn't get any warnings.
Well, in general, it is not possible, as the attributes are just added to the syntax tree elements, and then the tree is processed multiple times, and the processors may look for different attributes, and ignore other. The processors are not required to report that they have processed an attribute, or that they didn't find the expected one. The attribute semantics is very general, and all attributes by default are unnecessary.
However, you can build your own semantics on top of them. For example, the deriving
driver from the JaneStreet, will impose a restriction, that a preprocessor should exist:
# type t = Hello [@@deriving some];;
Cannot locate deriver some