Skip to content

Commit 5505247

Browse files
AlizterElectreAAS
andcommitted
fix(include-subdirs-qualified): prefer closer module of the same name
Co-authored-by: Ambre Austen Suhamy <[email protected]> Signed-off-by: Ali Caglayan <[email protected]>
1 parent 57601c7 commit 5505247

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/dune_rules/modules.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ module Group = struct
410410
fun acc modules m -> loop acc modules (Module.path m)
411411
;;
412412

413-
let parents (t : t) m = parents_modules [ t ] t.modules m
413+
(* [parents acc modules m] returns [acc] followed by all parent groups of
414+
module [m], ordered from innermost to outermost parent. *)
415+
let parents (t : t) m = parents_modules [ t ] t.modules m |> List.rev
414416

415417
module Memo_traversals = struct
416418
let rec parallel_map ({ alias; modules; name = _ } as t) ~f =
@@ -485,7 +487,10 @@ module Group = struct
485487
Ok (if Module_name.equal name (Module.name li) then [ li ] else [])
486488
| _ ->
487489
(* TODO don't recompute this *)
488-
let parents = parents t of_ |> List.map ~f:(fun g -> g.modules, Some g.name) in
490+
let parents =
491+
parents_modules [ t ] t.modules of_
492+
|> List.map ~f:(fun g -> g.modules, Some g.name)
493+
in
489494
Find_dep.find_dep_of_parents parents name
490495
;;
491496

test/blackbox-tests/test-cases/include-qualified/ambiguous-module-name.t

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
There is ambiguity between the two different foo modules.
2-
The behaviour is correct in the bootstrap process, but not in dune.
3-
It picks up the wrong one.
2+
The behaviour is now correct both in the bootstrap process, and in dune.
3+
It picks up the closest one.
44

55
$ echo "(lang dune 3.21)" > dune-project
66
$ cat > dune << EOF
@@ -14,7 +14,7 @@ It picks up the wrong one.
1414
> EOF
1515

1616
$ cat > foo.ml << EOF
17-
> let msg = "No"
17+
> let msg = "Failure"
1818
> EOF
1919

2020
$ mkdir bar
@@ -26,10 +26,6 @@ It picks up the wrong one.
2626
> let exported = Foo.msg ^ "!"
2727
> EOF
2828

29-
This is wrong, it should pick the closest module named foo.
29+
This is now fixed.
3030
$ dune exec ./main.exe
31-
File "bar/baz.ml", line 1, characters 15-22:
32-
1 | let exported = Foo.msg ^ "!"
33-
^^^^^^^
34-
Error: The module Foo is an alias for module Dune__exe__Foo, which is missing
35-
[1]
31+
Success!

test/blackbox-tests/test-cases/merlin/include-subdirs-qualified.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
(S $TESTCASE_ROOT/groupintf)
9898
(S $TESTCASE_ROOT/utils)
9999
(FLG (-w @1..3@5[email protected]@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g))
100-
(FLG (-open Foo__Groupintf__ -open Foo))
100+
(FLG (-open Foo -open Foo__Groupintf__))
101101
(UNIT_NAME foo__Groupintf__Calc))
102102
Calc: _build/default/groupintf/calc.ml
103103
((INDEX $TESTCASE_ROOT/_build/default/.foo.objs/cctx.ocaml-index)
@@ -109,7 +109,7 @@
109109
(S $TESTCASE_ROOT/groupintf)
110110
(S $TESTCASE_ROOT/utils)
111111
(FLG (-w @1..3@5[email protected]@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g))
112-
(FLG (-open Foo__Groupintf__ -open Foo))
112+
(FLG (-open Foo -open Foo__Groupintf__))
113113
(UNIT_NAME foo__Groupintf__Calc))
114114
Groupintf: _build/default/groupintf/groupintf
115115
((INDEX $TESTCASE_ROOT/_build/default/.foo.objs/cctx.ocaml-index)
@@ -121,7 +121,7 @@
121121
(S $TESTCASE_ROOT/groupintf)
122122
(S $TESTCASE_ROOT/utils)
123123
(FLG (-w @1..3@5[email protected]@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g))
124-
(FLG (-open Foo__Groupintf__ -open Foo))
124+
(FLG (-open Foo -open Foo__Groupintf__))
125125
(UNIT_NAME foo__Groupintf))
126126
Groupintf: _build/default/groupintf/groupintf.ml
127127
((INDEX $TESTCASE_ROOT/_build/default/.foo.objs/cctx.ocaml-index)
@@ -133,7 +133,7 @@
133133
(S $TESTCASE_ROOT/groupintf)
134134
(S $TESTCASE_ROOT/utils)
135135
(FLG (-w @1..3@5[email protected]@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g))
136-
(FLG (-open Foo__Groupintf__ -open Foo))
136+
(FLG (-open Foo -open Foo__Groupintf__))
137137
(UNIT_NAME foo__Groupintf))
138138
Main: _build/default/main
139139
((INDEX $TESTCASE_ROOT/_build/default/.foo.objs/cctx.ocaml-index)
@@ -169,7 +169,7 @@
169169
(S $TESTCASE_ROOT/groupintf)
170170
(S $TESTCASE_ROOT/utils)
171171
(FLG (-w @1..3@5[email protected]@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g))
172-
(FLG (-open Foo__Utils -open Foo))
172+
(FLG (-open Foo -open Foo__Utils))
173173
(UNIT_NAME foo__Utils__Calc))
174174
Calc: _build/default/utils/calc.ml
175175
((INDEX $TESTCASE_ROOT/_build/default/.foo.objs/cctx.ocaml-index)
@@ -181,6 +181,6 @@
181181
(S $TESTCASE_ROOT/groupintf)
182182
(S $TESTCASE_ROOT/utils)
183183
(FLG (-w @1..3@5[email protected]@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g))
184-
(FLG (-open Foo__Utils -open Foo))
184+
(FLG (-open Foo -open Foo__Utils))
185185
(UNIT_NAME foo__Utils__Calc))
186186
$ dune ocaml merlin dump-config utils

0 commit comments

Comments
 (0)