Skip to content

Commit a9981b5

Browse files
committed
Try to ensure future-proofness of references to polymorphic variants
Signed-off-by: Paul-Elliot <peada@free.fr>
1 parent 66ff396 commit a9981b5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/document/url.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ module Anchor = struct
263263
let page = Path.from_identifier parent in
264264
Ok { page; anchor = str_name; kind }
265265

266+
(* This is needed to ensure that references to polymorphic constructors have
267+
links that use the right suffix: those resolved references are turned into
268+
_constructor_ identifiers. *)
269+
let suffix_for_constructor x = x
270+
266271
let rec from_identifier : Identifier.t -> (t, Error.t) result =
267272
let open Error in
268273
function
@@ -362,7 +367,7 @@ module Anchor = struct
362367
| { iv = `Constructor (parent, name); _ } ->
363368
from_identifier (parent :> Identifier.t) >>= fun page ->
364369
let kind = `Constructor in
365-
let suffix = ConstructorName.to_string name in
370+
let suffix = suffix_for_constructor (ConstructorName.to_string name) in
366371
Ok (add_suffix ~kind page suffix)
367372
| { iv = `Field (parent, name); _ } ->
368373
from_identifier (parent :> Identifier.t) >>= fun page ->
@@ -415,7 +420,7 @@ module Anchor = struct
415420
add_suffix ~kind url suffix
416421
| Constructor { name; _ } ->
417422
let kind = `Constructor in
418-
let suffix = name in
423+
let suffix = suffix_for_constructor name in
419424
add_suffix ~kind url suffix)
420425

421426
(** The anchor looks like

src/model/paths.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,8 @@ module Reference = struct
963963
(label_parent_identifier r :> Identifier.t)
964964
| `Field (p, n) -> Identifier.Mk.field (field_parent_identifier p, n)
965965
| `PolyConstructor (s, n) ->
966+
(* Uses an identifier for constructor even though it is not
967+
one. Document must make the links correspond. *)
966968
Identifier.Mk.constructor
967969
((parent_type_identifier s :> Identifier.DataType.t), n)
968970
| `Constructor (s, n) ->

0 commit comments

Comments
 (0)