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

Cannot attach documentation to polymorphic variants #6966

Closed
vicuna opened this issue Aug 21, 2015 · 7 comments
Closed

Cannot attach documentation to polymorphic variants #6966

vicuna opened this issue Aug 21, 2015 · 7 comments

Comments

@vicuna
Copy link

vicuna commented Aug 21, 2015

Original bug ID: 6966
Reporter: @mmottl
Status: acknowledged (set by @damiendoligez on 2016-02-03T11:45:31Z)
Resolution: open
Priority: normal
Severity: feature
Target version: undecided
Category: ocamldoc
Monitored by: @gasche @diml @hcarty @mmottl

Bug description

Consider the following example "foo.ml":

type t =
  | A  (** Test *)

type u = [
  | `A  (** Test *)
]

Compiling the above with "ocamlc -w A foo.ml" will give the following warning:

File "foo.ml", line 5, characters 8-19:
Warning 50: unattached documentation comment (ignored)

Obviously, this only happens with the polymorphic variant and not the sum type. I think polymorphic variants should be treated the same way.

@vicuna
Copy link
Author

vicuna commented Aug 21, 2015

Comment author: @lpw25

The issue here is that the second form is a type equation not a type definition. It is not entirely clear why that form should be supported without also supporting:

  type t = int -> [`Foo (** the foo variant *) | `Bar (** the bar variant *) ]

  type t = int (** the foo parameter *)
             -> float (** the bar parameter *)
              -> string

  type t = int (** the first part *) * float (** the second part *)

@vicuna
Copy link
Author

vicuna commented Aug 21, 2015

Comment author: @mmottl

Fair enough, not sure whether the full generality of type equations should be supported. It's always possible to factor out the polymorphic variant part, e.g. with your example:

  type variant = [ `Foo  (** the foo variant *) | `Bar (** the bar variant *) ]
  type t = int -> variant

If we allow for special treatment of the case where the polymorphic variant is "immediate", then it becomes possible to document entries individually. It would be surprising to see a tuple or function with hundreds of entries, but having large polymorphic variant types with possibly thousands of entries can actually happen in practice with auto-generated code. It would be nice then to also have some documentation for each case in the API.

@vicuna
Copy link
Author

vicuna commented Aug 22, 2015

Comment author: @lpw25

My personal preference is to support something like:

  (** The type t.
      @variant `Foo The constructor of foos.
      @variant `Bar The constructor of bars. *)
   type t = [ `Foo | `Bar ]

This is slightly less convenient, but it leaves the somewhat ad-hoc decision about which parts of type equations can be documented to the documentation tool rather than the compiler.

I hope to add support for something like this to the (not yet released) codoc tool.

@vicuna
Copy link
Author

vicuna commented Aug 23, 2015

Comment author: @mmottl

That's a possibility and somewhat similar to using @param for describing function parameters. The downside is that the documentation and the code are then separate, making it more likely that developers forget about the documentation, especially when new cases are added.

The current documentation system may not be expressive enough to fully cover all syntactic constructs. I believe there were some ideas for a standardized documentation system built on attributes as introduced in OCaml 4.02. Not sure what happened to this proposal.

@yallop
Copy link
Member

yallop commented Apr 8, 2019

This is a duplicate of #4347.

@trefis
Copy link
Contributor

trefis commented Apr 8, 2019

What's more, it's been fixed by #477.

@trefis trefis closed this as completed Apr 8, 2019
@trefis
Copy link
Contributor

trefis commented Apr 8, 2019

That is, the compiler side of things has been fixed: the docstring is now attached as an attributed in the AST.
Additionally, I doubt that any work will happen on ocamldoc related to that issue (but it should happen on odoc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants