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

Doc comment dropped from empty .mli file #7701

Closed
vicuna opened this issue Dec 29, 2017 · 2 comments
Closed

Doc comment dropped from empty .mli file #7701

vicuna opened this issue Dec 29, 2017 · 2 comments

Comments

@vicuna
Copy link

vicuna commented Dec 29, 2017

Original bug ID: 7701
Reporter: antron
Assigned to: @lpw25
Status: resolved (set by @gasche on 2018-05-05T14:00:49Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.06.0
Fixed in version: 4.07.0+dev/beta2/rc1/rc2
Category: typing
Duplicate of: #7138
Monitored by: @gasche

Bug description

When an .mli file consists of only a (** ... *) comment, the comment does not appear in the signature item list of the signature read from the corresponding .cmti file. By contrast, if the signature includes a comment and some other items, the comment appears in the signature item list.

Steps to reproduce

empty.mli:

(** This comment will be lost by the compiler. *)

nonempty.mli:

(** This comment will be kept by the compiler. *)

val foo : unit

count_sig_items.ml:

let () =
let file = Sys.argv.(1) in
let cmt = Cmt_format.read_cmt file in
match cmt.cmt_annots with
| Interface signature ->
signature.Typedtree.sig_items
|> List.length
|> string_of_int
|> print_endline
| _ ->
assert false

Makefile:

.PHONY : reproduce
reproduce :
ocamlc -version
ocamlc -bin-annot -o empty.cmi -c empty.mli
ocamlc -bin-annot -o nonempty.cmi -c nonempty.mli
ocamlfind opt -linkpkg -package compiler-libs.common count_sig_items.ml
./a.out empty.cmti
./a.out nonempty.cmti

.PHONY : clean
clean :
rm -f *.cmi *.cmti *.cmx *.o a.out

Running this (make), the output is:

ocamlc -version
4.06.0
ocamlc -bin-annot -o empty.cmi -c empty.mli
ocamlc -bin-annot -o nonempty.cmi -c nonempty.mli
ocamlfind opt -linkpkg -package compiler-libs.common count_sig_items.ml
./a.out empty.cmti
0
./a.out nonempty.cmti
2

I would expect the output to be 1, 2.

@vicuna
Copy link
Author

vicuna commented Jan 6, 2018

Comment author: @Octachron

A quick workaround for this issue is to add two empty new lines before the documentation comment.

For a more robust fix, see #1562 .

@vicuna
Copy link
Author

vicuna commented May 5, 2018

Comment author: @gasche

After another iteration, a fix was merged from

#1693

which I am currently working on backporting into 4.07.

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

2 participants