Skip to content

Commit e6a4358

Browse files
committed
test: document module name shadowing between stanza and library
When an internal module name shadows an unwrapped library's module name, the internal module takes precedence and the library's module is inaccessible. This means ocamldep will report the internal module, not the library's, so dependency filtering that treats stanza-internal names as non-library references is correct. Signed-off-by: Robin Bate Boerop <me@robinbb.com>
1 parent dfb865d commit e6a4358

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Test that when a stanza's internal module name shadows a library module name,
2+
the internal module takes precedence. This validates that ocamldep-based
3+
dependency filtering (which treats names found in stanza_modules as internal)
4+
correctly reflects the compiler's resolution order.
5+
6+
See: https://github.com/ocaml/dune/issues/4572
7+
8+
$ cat > dune-project <<EOF
9+
> (lang dune 3.0)
10+
> EOF
11+
12+
--- Unwrapped library: internal module shadows library module ---
13+
14+
An unwrapped library exposes module Helper. The executable also has a module
15+
named Helper. The internal module takes precedence — the library's Helper is
16+
inaccessible.
17+
18+
$ mkdir unwrapped_lib
19+
$ cat > unwrapped_lib/dune <<EOF
20+
> (library
21+
> (name unwrapped_lib)
22+
> (wrapped false))
23+
> EOF
24+
25+
$ cat > unwrapped_lib/helper.ml <<EOF
26+
> let lib_value = 42
27+
> EOF
28+
29+
$ cat > unwrapped_lib/helper.mli <<EOF
30+
> val lib_value : int
31+
> EOF
32+
33+
$ cat > dune <<EOF
34+
> (executable
35+
> (name main)
36+
> (libraries unwrapped_lib))
37+
> EOF
38+
39+
$ cat > helper.ml <<EOF
40+
> let local_value = 1
41+
> EOF
42+
43+
$ cat > main.ml <<EOF
44+
> let () = print_int Helper.local_value
45+
> EOF
46+
47+
The build succeeds using the internal Helper:
48+
49+
$ dune build ./main.exe
50+
51+
The library's Helper.lib_value is not accessible:
52+
53+
$ cat > main.ml <<EOF
54+
> let () = print_int Helper.lib_value
55+
> EOF
56+
57+
$ dune build ./main.exe 2>&1
58+
File "main.ml", line 1, characters 19-35:
59+
1 | let () = print_int Helper.lib_value
60+
^^^^^^^^^^^^^^^^
61+
Error: Unbound value Helper.lib_value
62+
[1]

0 commit comments

Comments
 (0)