OCaml warning 31, compiler-libs, and ppx

不打扰是莪最后的温柔 提交于 2019-12-06 07:18:58

This error of Warning 31 is a new default behaviour of ocaml 4.03.0 compiler.

OCaml gives you Warning 31 when you link two modules of the same name. This is not specific to 4.03.0:

$ touch a.ml
$ ocamlc a.ml a.ml
File "a.cmo", line 1:
Warning 31: files a.cmo and a.cmo both define a module named A
File "a.ml", line 1:
Error: Some fatal warnings were triggered (1 occurrences)  <-- This is new in 4.03.0

OCaml 4.02.3 does not handle Warning 31 as an error by default, but OCaml 4.03.0 does:

$ ocamlc -v
The OCaml compiler, version 4.03.0
Standard library directory: /Users/XXX/.opam/4.03.0/lib/ocaml
$ ocamlc -help
...
  -warn-error <list>  Enable or disable error status for warnings according
     to <list>.  See option -w for the syntax of <list>.
     Default setting is "-a+31"

+31 makes Warning 31 error. In OCaml 4.02.3, the default setting is "-a". That's why your code is rejected not by 4.02.3 but by 4.03.0.

A workaround is to remove +31 from -warn-error switch. But the best in general is to rename your module. People have had many linking troubles hard to track down by having more than one module with the same name, and this is why 31 is now an error by default.

Additional note

Warning 31 is not a compile time warning but a link time one. Therefore if you use ocamlbuild, you have to specify -warn-error -a with -lflags instead of -cflags.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!