Reputation: 9805
I have the below OCaml file which compiles correctly without ppx
and fails with this dune
file
(library
(name so_proj)
(preprocess
(pps
ppx_inline_test
ppx_deriving.show
ppx_deriving.ord
ppx_deriving.map
ppx_deriving.eq
ppx_deriving.fold
ppx_deriving.iter)))
and works with
(library
(name so_proj))
the error being
File "SO_naming_existential.ml", line 23, characters 16-18:
23 | fun (Mod (type xr) (m : xr)) ->
^^
Error: migration error: existentials in pattern-matching is not supported before OCaml 4.13
here's the OCaml file in question which uses a new syntax (and provides an equivalent - I believe - version when it's not available)
type existentiel = Mod : 'x -> existentiel
module type existentiel_m = sig
type x
val value : x
end
let to_Module : existentiel -> (module existentiel_m) =
fun (Mod m) ->
let namedxr : type xr. xr -> (module existentiel_m) =
fun v ->
(module struct
type x = xr
let value = v
end)
in
namedxr m
(* Since 4.13 https://github.com/ocaml/ocaml/pull/9584 *)
let to_Module2 : existentiel -> (module existentiel_m) =
fun (Mod (type xr) (m : xr)) ->
(module struct
type x = xr
let value = m
end)
To confirm the origin of the error (and to run first for avoiding to waste time..) the command
dune build --verbose
points indeed at an error happening in ppx
Running[2]: (cd _build/default && .ppx/0789030747a4993265eb655c993f5cab/ppx.exe --cookie 'inline_tests="enabled"' --cookie 'library-name="so_proj"' -o SO_naming_existential.pp.ml --impl SO_naming_existential.ml -corrected-suffix .ppx-corrected -diff-cmd - -dump-ast)
Command [2] exited with code 1:
$ (cd _build/default && .ppx/0789030747a4993265eb655c993f5cab/ppx.exe --cookie 'inline_tests="enabled"' --cookie 'library-name="so_proj"' -o SO_naming_existential.pp.ml --impl SO_naming_existential.ml -corrected-suffix .ppx-corrected -diff-cmd - -dump-ast)
File "SO_naming_existential.ml", line 23, characters 16-18:
23 | fun (Mod (type xr) (m : xr)) ->
^^
Error: migration error: existentials in pattern-matching is not supported before OCaml 4.13
Can one force ppx
to use 4.13, or get a warning when a ppx is not compatible with a given version ? (or is it a bug ?)
Upvotes: 1
Views: 205
Reputation: 35210
An executable or a library could only be composed of compilation units that are compiled by the same compiler. In other words, you can't build some parts of your project with one compiler and the other parts with another.
When you compile an OCaml project using dune the compiler is searched in the in the directories specified in your PATH variable (in Linux). You can see which compiler is selected using the shell command which ocaml
. And ocaml -version
will tell you its version.
If you're using opam (most likely you are), then you can install the required version of the compiler using the following shell command,
opam switch create 4.13.1
once it is finished, activate the created switch with
eval $(opam env)
This will ensure that the newly installed version of OCaml is available in your path. Double-check that using which ocaml
and ocaml -version
.
Finally, install the dependencies required by your project with opam install
and rebuild the project.
Upvotes: 2