While updating a personal project to use dune, I started to get syntax errors in the .ml files generated by menhir. The problem occurs because dune calls menhir with the --infer-read-only
option, which causes menhir to infer types by running ocamlc -i
. If those types have the form _[> `Foo of 'weak1]
then later calls by dune to ocamldep fail.
A more direct way to replicate the problem is to create the following file.
(* test.ml *)
let foo_only = List.filter_map (function `Foo e -> Some e | _ -> None)
and then run
ocamlc -i test.ml > test.mli; ocamldep test.mli
which fails with
File "test.mli", line 1, characters 16-18:
1 | val foo_only : _[> `Foo of '_weak1 ] list -> '_weak1 list
^^
Error: Syntax error
In this form, a simple fix is easy to see. Eta expanding to let foo_only x = ... x
produces a signature without a weak type variable.
The problem is harder to diagnose, however, in the original context. E.g., it can be reproduced by editing merlin/demos/calc/parser.mly
:
%{ let foo_only = List.filter_map (function `Foo e -> Some e | _ -> None) %}
...
main:
| e = foo EOL
{ List.hd (foo_only [e]) }
foo:
| e = expr
{ `Foo e }
My question is: where is the best place to fix this problem? Could/should ocamlc -i
fail or eliminate the weak type variables?