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

When warning 60 is activated, a used module is reported as "unused" #7684

Closed
vicuna opened this issue Dec 1, 2017 · 7 comments
Closed

When warning 60 is activated, a used module is reported as "unused" #7684

vicuna opened this issue Dec 1, 2017 · 7 comments

Comments

@vicuna
Copy link

vicuna commented Dec 1, 2017

Original bug ID: 7684
Reporter: Iguernlala
Status: acknowledged (set by @gasche on 2017-12-01T21:06:14Z)
Resolution: open
Priority: normal
Severity: minor
Version: 4.06.0
Category: misc
Monitored by: @nojb

Bug description

This happens with mutually recursive modules as shown in the example below. Module X1 is used in module M, and module M is exported in the interface. But, if warning 60 is set, an "unused module X1" warning is triggered when compiling as follows:

$ ocamlc -c -w +60 foo.mli foo.ml

File "foo.ml", line 8, characters 0-43:
Warning 60: unused module X1.

(* content of foo.ml *)
module type S = sig
type t
end

module rec M : S = struct
type t = X1 of X1.t
end
and X1 : S = struct
type t = M.t list
end

(* content of foo.mli *)
module type S = sig
type t
end

module M : S

@vicuna
Copy link
Author

vicuna commented Dec 1, 2017

Comment author: @gasche

Reproduced under 4.06.0.

@vicuna
Copy link
Author

vicuna commented Dec 5, 2017

Comment author: Iguernlala

I forgot to say that trying to disable this warning with an annotation [@@@ocaml.warning "-60"] did not work

[Edited]
Actually, I manage to disable the warning if I put the annotation before 'module rec M ...'. (I had tried to put the annotation before 'and module X1 ...' previously)

@vicuna
Copy link
Author

vicuna commented Dec 27, 2017

Comment author: @mshinwell

Here is another, probably related, example which I came across this week.

w60.ml

module type S = sig val f : unit -> unit end

module F (X : S) = struct let f () = X.f () end

module rec A : S =
F (struct let f () = B.f () end)
and B : S =
F (struct let f () = failwith "ok" end)

let f = A.f

let () = f ()

w60.mli

val f : unit -> unit

Using a recent trunk:

$ ocamlc w60.mli
$ ocamlc -w +60 -o w60 w60.ml
File "w60.ml", line 7, characters 0-42:
Warning 60: unused module B.
$ ./w60
Fatal error: exception Failure("ok")

The warning is bogus, as evidenced by the exception, which shows that [B] was used.

The bogus warning does not appear if the .mli file is absent.

@vicuna
Copy link
Author

vicuna commented Dec 27, 2017

Comment author: @mshinwell

As an aside: the following version produces a runtime exception:

Fatal error: exception Undefined_recursive_module("w60.ml", 23, 2)

This surprised me at first, but it appears to be related to Mantis 2629. It would indeed be nice if there were a compile-time check for this as suggested in that issue:

module type S = sig val f : unit -> unit end

module F (X : S) = struct let f = X.f end

module rec A : S =
F (struct let f = B.f end)
and B : S =
F (struct let f () = failwith "ok" end)

let f = A.f

let () = f ()

@jberdine
Copy link
Contributor

Duplicate of #7522 ?

@vicuna vicuna added the bug label Mar 20, 2019
@github-actions
Copy link

github-actions bot commented May 7, 2020

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label May 7, 2020
@lpw25
Copy link
Contributor

lpw25 commented May 7, 2020

This was fixed by #9393

@lpw25 lpw25 closed this as completed May 7, 2020
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

4 participants