Skip to content

Commit de54ed2

Browse files
panglesdjonludlam
authored andcommitted
Try to ensure future-proofness of references to polymorphic variants
Signed-off-by: Paul-Elliot <peada@free.fr>
1 parent 15f8329 commit de54ed2

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
@@ -272,6 +272,11 @@ module Anchor = struct
272272
let page = Path.from_identifier parent in
273273
Ok { page; anchor = str_name; kind }
274274

275+
(* This is needed to ensure that references to polymorphic constructors have
276+
links that use the right suffix: those resolved references are turned into
277+
_constructor_ identifiers. *)
278+
let suffix_for_constructor x = x
279+
275280
let rec from_identifier : Identifier.t -> (t, Error.t) result =
276281
let open Error in
277282
function
@@ -371,7 +376,7 @@ module Anchor = struct
371376
| { iv = `Constructor (parent, name); _ } ->
372377
from_identifier (parent :> Identifier.t) >>= fun page ->
373378
let kind = `Constructor in
374-
let suffix = ConstructorName.to_string name in
379+
let suffix = suffix_for_constructor (ConstructorName.to_string name) in
375380
Ok (add_suffix ~kind page suffix)
376381
| { iv = `Field (parent, name); _ } ->
377382
from_identifier (parent :> Identifier.t) >>= fun page ->
@@ -424,7 +429,7 @@ module Anchor = struct
424429
add_suffix ~kind url suffix
425430
| Constructor { name; _ } ->
426431
let kind = `Constructor in
427-
let suffix = name in
432+
let suffix = suffix_for_constructor name in
428433
add_suffix ~kind url suffix)
429434

430435
(** The anchor looks like

src/model/paths.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,8 @@ module Reference = struct
987987
(label_parent_identifier r :> Identifier.t)
988988
| `Field (p, n) -> Identifier.Mk.field (field_parent_identifier p, n)
989989
| `PolyConstructor (s, n) ->
990+
(* Uses an identifier for constructor even though it is not
991+
one. Document must make the links correspond. *)
990992
Identifier.Mk.constructor
991993
((parent_type_identifier s :> Identifier.DataType.t), n)
992994
| `Constructor (s, n) ->

0 commit comments

Comments
 (0)