Skip to content

Commit 36ea0c9

Browse files
committed
Warn when synopses in {!modules} lists contain references
These references need to be resolved from their containing module's environment, which is only available when linking that module.
1 parent b51ad7c commit 36ea0c9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/xref2/link.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ let synopsis_of_module env (m : Component.Module.t) =
2828
| Ok sg -> synopsis_from_comment (Component.extract_signature_doc sg)
2929
| Error _ -> None)
3030

31+
let warn_if_contains_references ~location p =
32+
let is_ref = function
33+
| { Location_.value = `Reference _; _ } -> true
34+
| _ -> false
35+
in
36+
match p with
37+
| Some p when List.exists is_ref p ->
38+
Lookup_failures.with_location location (fun () ->
39+
Lookup_failures.report ~kind:`Warning
40+
"The synopsis from this module contains references that won't be \
41+
resolved when included in this list.")
42+
| _ -> ()
43+
3144
exception Loop
3245

3346
let rec is_forward : Paths.Path.Module.t -> bool = function
@@ -175,6 +188,7 @@ and comment_nestable_block_element env parent
175188
| Some (r, _, m) ->
176189
let module_reference = Location_.at location (`Resolved r)
177190
and module_synopsis = synopsis_of_module env m in
191+
warn_if_contains_references ~location module_synopsis;
178192
{ Comment.module_reference; module_synopsis }
179193
| None -> r)
180194
refs

test/xref2/module_list.t/run.t

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Testing {!modules:...} lists
22

33
$ compile external.mli starts_with_open.mli main.mli
4+
File "external.mli", line 20, characters 4-36:
5+
The synopsis from this module contains references that won't be resolved when included in this list.
6+
File "main.mli", line 1, character 4 to line 3, character 47:
7+
The synopsis from this module contains references that won't be resolved when included in this list.
8+
File "main.mli", line 1, character 4 to line 3, character 47:
9+
The synopsis from this module contains references that won't be resolved when included in this list.
410

511
Everything should resolve:
612

0 commit comments

Comments
 (0)