Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on reference to ambiguous label #781

Merged
merged 3 commits into from
Nov 23, 2021

Conversation

jonludlam
Copy link
Member

We already warn when defining an explicit label that conflicts with another,
but this PR adds a warning when trying to reference a label that is ambiguous.

@jonludlam jonludlam force-pushed the ambiguous-ref-warning branch from d0d815b to c99c8d8 Compare November 19, 2021 13:32
Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good :)

src/xref2/env.ml Outdated
| ([ x ] as results), Some c -> (
record_lookup_results env results;
match c env x with
| Some (`Ambiguous (x, y)) -> Result.Error (`Ambiguous (x, y))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| Some (`Ambiguous (x, y)) -> Result.Error (`Ambiguous (x, y))
| Some (`Ambiguous _ as e) -> Result.Error e

let ambiguous_warning name (results : [< Component.Element.any ] list) =
let results = (results :> Component.Element.any list) in
if List.for_all (function `Label _ -> true | _ -> false) results then
ambiguous_label_warning name (results :> [> Component.Element.any ] list)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cast is unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes! thanks, this was left in from when I was trying to return a different `AmbiguousLabel error (which ultimately failed, predictably in hindsight).

in

Identifier.Maps.Label.add identifier err env.ambiguous_labels
| Some _ -> assert false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid this assert, we could use lookup_by_id s_label, which also return useful data in the ambiguous case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this assert is in place of what I actually want, which is a type error. You're right, we could avoid this assert with s_label, but s_label just does:

(function #Component.Element.label as r -> Some r | _ -> None)

so I could get the same effect by having just Some _ -> env.ambiguous_labels. I don't like we've got a runtime instead of a compile time error here, but I like ignoring the error entirely even less :-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

We already warn when defining an explicit label that conflicts with another,
but this PR adds a warning when trying to reference a label that is ambiguous.
@jonludlam jonludlam force-pushed the ambiguous-ref-warning branch from 0473bf0 to 6c40226 Compare November 23, 2021 10:48
@jonludlam jonludlam merged commit 31330b8 into ocaml:master Nov 23, 2021
jonludlam added a commit to jonludlam/opam-repository that referenced this pull request Nov 26, 2021
CHANGES:

Bugs fixed
- Man page renderer fails to output pages that have children (@jonludlam, @Julow, ocaml/odoc#766)
- Fix resolution of unprefixed references to pages (@Julow, ocaml/odoc#755)
- Fix reporting of ambiguous labels (@Julow, @jonludlam, ocaml/odoc#773, ocaml/odoc#781)
- Allow referencing of labels in the top comment (@jonludlam, ocaml/odoc#771)

Additions
- Strip unquoted spaces in identifiers for a more flexible reference syntax (@lubega-simon, @panglesd, ocaml/odoc#783)
- Add context to messages raised in expansions of includes (@Julow, ocaml/odoc#780)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants