-
Notifications
You must be signed in to change notification settings - Fork 114
Do not splice the type name into constructor and field references #1468
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
Open
MavenRain
wants to merge
2
commits into
ocaml:master
Choose a base branch
from
MavenRain:372-reference-type-splice
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| type t = Alpha | Beta | ||
|
|
||
| type r = { fld : int } | ||
|
|
||
| (** The type is dropped whether or not the reference spelled it out: | ||
| {!Alpha}, {!constructor-Alpha}, {!t.Alpha}, {!t.constructor-Alpha}, | ||
| {!fld}, {!field-fld} and {!r.fld}. *) | ||
|
|
||
| module Bla : sig | ||
| type ha = Alpha | Beta | ||
|
|
||
| type ra = { fla : int } | ||
|
|
||
| type sw = [ `On | `Off ] | ||
|
|
||
| type ext = .. | ||
|
|
||
| type ext += Ext_a | ||
|
|
||
| exception Exn_a | ||
|
|
||
| module Inner : sig | ||
| type i = Gamma | ||
| end | ||
| end | ||
|
|
||
| (** The module path is kept: {!Bla.Alpha} and {!Bla.ha.Alpha} both render as | ||
| [Bla.Alpha]; {!Bla.fla} and {!Bla.ra.fla} both render as [Bla.fla]. | ||
|
|
||
| Polymorphic constructors lose the type as well: {!Bla.sw.On} and | ||
| {!Bla.sw.`Off}. | ||
|
|
||
| Only the type component is dropped, not the enclosing modules: | ||
| {!Bla.Inner.Gamma} and {!Bla.Inner.i.Gamma}. | ||
|
|
||
| Parents that are not types are left alone: {!Bla.Ext_a}, {!Bla.Exn_a}, | ||
| {!Bla.ha} and {!Bla.Inner.i}. | ||
|
|
||
| When the reference carries its own text, the rendered path becomes the | ||
| tooltip instead: {{!Bla.Alpha} the first case}. *) | ||
|
|
||
| module Ambiguous : sig | ||
| type a = Same | ||
|
|
||
| type b = Same | ||
| end | ||
|
|
||
| (** Two types of a same module may share a constructor name; the rendered text | ||
| is then the same for both and only the anchor tells them apart: | ||
| {!Ambiguous.a.Same} and {!Ambiguous.b.Same}. *) | ||
|
|
||
| class cls : object end | ||
|
|
||
| (** An unresolved reference is still printed as it was written: {!cls.Alpha} *) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| The name of a type is not part of the OCaml path of its constructors and of | ||
| its fields, so it must not be spliced into the text a reference is rendered | ||
| as: [M.t.Foo] is not valid syntax whereas [M.Foo] is. | ||
| See https://github.com/ocaml/odoc/issues/372 | ||
|
|
||
| $ ocamlc -c -bin-annot a.mli | ||
| $ odoc compile --warn-error -I . a.cmti | ||
|
|
||
| Only the reference whose parent is a class fails to resolve: | ||
|
|
||
| $ odoc link a.odoc | ||
| File "a.mli", line 54, characters 64-76: | ||
| Warning: Failed to resolve reference unresolvedroot(cls).Alpha Couldn't find "Alpha" | ||
|
|
||
| $ odoc html-generate --output-dir html --indent a.odocl | ||
|
|
||
| Constructors and fields are qualified by their module path only, never by the | ||
| name of their type. Extensions, exceptions and types keep their parent, and | ||
| the anchors are unaffected: | ||
|
|
||
| $ cat html/A/index.html | grep '<a href' | grep '<code>' | ||
| <a href="#type-t.Alpha"><code>Alpha</code></a>, | ||
| <a href="#type-t.Alpha"><code>Alpha</code></a>, | ||
| <a href="#type-t.Alpha"><code>Alpha</code></a>, | ||
| <a href="#type-t.Alpha"><code>Alpha</code></a>, | ||
| <a href="#type-r.fld"><code>fld</code></a>, | ||
| <a href="#type-r.fld"><code>fld</code></a> and | ||
| <a href="#type-r.fld"><code>fld</code></a>. | ||
| <a href="Bla/index.html#type-ha.Alpha"><code>Bla.Alpha</code></a> | ||
| and <a href="Bla/index.html#type-ha.Alpha"><code>Bla.Alpha</code></a> | ||
| <a href="Bla/index.html#type-ra.fla"><code>Bla.fla</code></a> and | ||
| <a href="Bla/index.html#type-ra.fla"><code>Bla.fla</code></a> both | ||
| <a href="Bla/index.html#type-sw.On"><code>Bla.`On</code></a> and | ||
| <a href="Bla/index.html#type-sw.Off"><code>Bla.`Off</code></a>. | ||
| <a href="Bla/Inner/index.html#type-i.Gamma"><code>Bla.Inner.Gamma</code> | ||
| <a href="Bla/Inner/index.html#type-i.Gamma"><code>Bla.Inner.Gamma</code> | ||
| <a href="Bla/index.html#extension-Ext_a"><code>Bla.Ext_a</code></a> | ||
| , <a href="Bla/index.html#exception-Exn_a"><code>Bla.Exn_a</code></a> | ||
| , <a href="Bla/index.html#type-ha"><code>Bla.ha</code></a> and | ||
| <a href="Bla/Inner/index.html#type-i"><code>Bla.Inner.i</code></a> | ||
| <a href="Ambiguous/index.html#type-a.Same"><code>Ambiguous.Same</code> | ||
| <a href="Ambiguous/index.html#type-b.Same"><code>Ambiguous.Same</code> | ||
|
|
||
| With its own text, the reference is rendered as the tooltip: | ||
|
|
||
| $ cat html/A/index.html | grep -o 'title="[^"]*"' | ||
| title="Bla.Alpha" | ||
|
|
||
| An unresolved reference is still printed exactly as it was written, and is | ||
| not turned into a link: | ||
|
|
||
| $ cat html/A/index.html | grep 'cls.Alpha' | ||
| <code>cls.Alpha</code> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 it would improve the readability if we replaced at least the identifier with a type:
(or something like that)
I don't think we can do the same with the rest of the clauses, but it is fine to keep them explicitly matched.