1

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.

anol
  • 8,264
  • 3
  • 34
  • 78

1 Answers1

2

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
ivg
  • 34,431
  • 2
  • 35
  • 63
  • I suppose that writing a ppx that would capture any attribute and report them all would not be feasible? I could consider that any remaining attributes are undesirable in my program, and apply such a ppx as the last transformer in my chain. – anol Jan 09 '17 at 18:47
  • yeah, you can write a preprocessor, that will issue a warning for each unknown attribute (except whitelisted). – ivg Jan 10 '17 at 17:22