The explanation of the open!
syntax seems to be incomplete. The manual states:
Since OCaml 4.01, open statements shadowing an existing identifier (which is later used) trigger the warning 44. Adding a ! character after the open keyword indicates that such a shadowing is intentional and should not trigger the warning.
Looking at the manual, we see:
Warning 44: Open statement shadows an already defined identifier.
However, in testing, I’ve found that adding open!
will not only disable warning 44, but also warning 33.
Warning 33: Unused open statement.
I’ve constructed a minimal example which shows the description about open!
to be incomplete:
(* main.ml *)
let foo = "abc"
module Bar = struct
let foo = "xyz"
end
open Bar
let () = print_endline foo
…
Compiling with
$ ocamlc -w +33+44 -c main.ml
will trigger warning 44 because module Bar
contains a value foo
which is shadowed, and then used.
…
And changing
let () = print_endline foo
to
let () = print_endline "foo"
will trigger warning 33 because the Bar
module is no longer used.
…
However, if you change
open Bar
to
open! Bar
then neither warning will be triggered regardless of whether foo
or "foo"
is used.
…
I have confirmed this to be the case with compiler versions 4.03.0, 4.04.1, and 4.05.0