Skip to content

Doc comment dropped from empty .mli file #7701

Closed

Description

@vicuna

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.

Activity

  1. vicuna commented on Jan 6, 2018

    @vicuna
    Author

    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 .

  2. vicuna commented on May 5, 2018

    @vicuna
    Author

    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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions