I have a project, called ‘devmap’, with a tests directory. I’m developing a helper module, docker_client.ml, in that directory. I have the following files: docker_client_types.ml, docker_client.mli, docker_client.ml. The types file contains some shared type definitions.
The first line of docker_client.mli is
include module type of Docker_client_types
The first line of docker_client.ml is
include Docker_client_types
I have dune build --watch running in the project’s root.
I added the following to test_devmap.ml top get the compilation to look at these other files:
open Docker_client
Docker_client_types.ml itself looks fine.
In docker_client.mli, Docker_client_types is an unbound module.
In docker_client.ml, Docker_Client_types produces a minibuffer error
Internal path Dune__exe__Docker_client_types is dangling.
The compiled interface for module Dune__exe__Docker_client_types
was not found.
What does this error mean and how do I fix it? What does it mean that it’s “dangling”?
The dune build --watch process doesn’t report this error.
Update: problem is resolved after a few changes, and I believe the compilation just wasn’t able to proceed far enough for that shared file to be made available for inclusion in the other two.
I’m pretty sure this is related to ppx_deriving_yojson and some bugs in my code. One bug was that I’d left a [@@deriving of_yojson] on one of the types when moving it to the shared types file. I imagine this broke the .mli file including it, and I suppose broke the compilation tree enough that the shared file never got completely compiled or something.
Another bug, though I don’t know if it’s a bug in my code or the ppx, is that in the downstream .ml file I had two types defined using and:
open Base
module Client = Cohttp_eio.Client
type t = {
config: config;
client: Client.t
}
and some_other_type = {
... some fields ...
} [@@deriving of_yojson]
I switched from merlin to ocaml-eglot, which cleared up the problem in the .mli file, but in this .ml file there remained an error under open Base about a missing Client.of_yojson. I stared at this for a while, because I wasn’t trying to derive an of_yojson function on any type containing a Client.t. On a hunch, I replaced the and with type, decoupling it the second type from the type above containing the Client.t. This cleared up the error. The error never appeared in the dune build -w output.
Is this a bug in the ppx? In the lsp server? Or is this defined behavior I don’t understand?
Maybe too specific a problem to be useful for posterity, but I’ll leave it here in case.
For posterity, one remedy that does seem to shake things loose in this situation (which occurred again after I made a change to the shared file while there was an error in the mli file, causing the other downstream file not to see the shared file even after I fixed he mli file), the solution is to restart the lsp-server. Using ocaml-eglot, this is M-x eglot, which will confirm that you want to kill the current session and start a new one.