-
Notifications
You must be signed in to change notification settings - Fork 97
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
Conversation
d0d815b
to
c99c8d8
Compare
There was a problem hiding this 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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Some (`Ambiguous (x, y)) -> Result.Error (`Ambiguous (x, y)) | |
| Some (`Ambiguous _ as e) -> Result.Error e |
src/xref2/ref_tools.ml
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cast is unnecessary.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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.
0473bf0
to
6c40226
Compare
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)
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.