morally-incorrect "unused variable" warnings
foo.mly:
%token TOKEN
%start start
%type <Lexing.position * Lexing.position> start
%%
start:
| tok=TOKEN { $loc(tok) }
;
$ menhir --ocamlc "ocamlc -w +27" --infer /tmp/foo.mly
File "/tmp/foo.mly", line 9, characters 2-5:
Warning 27 [unused-var-strict]: unused variable tok.
Menhir generates code that does not use the variable tok
(which denotes the semantic value of the token), but the semantic action does use the variable.
I think that the code generator for $macro(foo)
should be tuned to include an ignore foo
call, to silence this warning.
One can of course disable the warning globally for the whole file (menhir could do it by adding a well-chosen attribute, or I could do it by tweaking the build system), but this risks silencing warnings in the semantic actions that do in fact correspond to code-quality issues that the users wants to know about.
(I wondered if this was hopeless because Menhir generates too many unused-variable warnings anyway. But I think not: I observed the present issue when modifying the Menhir grammar in the OCaml compiler, which means that it currently compiles fine with the warning enabled. This is evidence that large, non-trivial Menhir grammars can compile with this flag enabled, at least when using the --table backend.)