Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbound module for library if library name the same as test name #778

Open
jakzale opened this issue Jul 9, 2022 · 1 comment
Open

Unbound module for library if library name the same as test name #778

jakzale opened this issue Jul 9, 2022 · 1 comment

Comments

@jakzale
Copy link

jakzale commented Jul 9, 2022

Problem

If the name of a test/executable in dune is the same as its library dependency, then ocamllsp will report Unbound module for that library, but dune build, dune runtest, or dune exec will work just fine.

Unfortunately, dune init project <name> uses a template with the same name for library and a test, which potentially can lead to confusion for newcomers.

Versions

ocaml 4.14.0
dune 3.3.1
ocamllsp 1.12.2

Tested in Visual Studio Code 1.69.0, using OCaml Platform v1.10.7.

Steps to Reproduce

1. Create a project from dune's default template

$ touch dune-workspace
$ dune init project example
Success: initialized project component named example
$ dune build

2. Create a module in the library

Put the following in example/lib/foo.ml:

let foo () =
  print_endline "Hello, world!"

3. Use the module in a test

Update example/test/dune to following:

(test
 (name example)
 (libraries example))

Update example/test/example.ml to following

let () =
  Example.Foo.foo ()

4. Run tests

$ dune runtest
Hello, world!

Bug?

Even though dune runtest works fine, ocamllsp reports Unbound module Example in example/test/example.ml:

image

Potential Workaround

Renaming the test to a different (i.e. test_example) by changing the name field in example/test/dune:

(test
 (name test_example)
 (libraries example))

and changing the name of the file

$ git mv example/test/example.ml example/test/test_example.ml

Fixes the problem.

@jbulow
Copy link

jbulow commented Jul 31, 2023

This still seems to be a problem. Should the dune init template be updated or should it be documented somewhere?

It is a bit confusing with the current situation when the init template is broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants