-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Wrong module type signature grabbed when using packed libraries #6433
Description
Original bug ID: 6433
Reporter: @mmottl
Assigned to: @garrigue
Status: acknowledged (set by @garrigue on 2014-05-20T02:55:29Z)
Resolution: open
Priority: normal
Severity: feature
Version: 4.01.0
Target version: undecided
Category: typing
Duplicate of: #6305
Monitored by: @gasche @hcarty @Chris00 @mmottl
Bug description
I'm not sure to which extent this qualifies as a bug, but it's at least annoying behavior:
Lets assume you want to pack several modules into a library module "Foo", e.g. module "Utils":
ocamlopt -c -for-pack Foo utils.ml
Some functionality in the packed modules may only be used internally so you may want to hide it by defining an interface file "foo.mli", which would be compiled as usual:
ocamlopt -c foo.mli
Finally, we pack and create the library "Foo":
ocamlopt -pack utils.cmx -o foo.cmx
ocamlopt -a foo.cmx -o foo.cmxa
Here is the problem: lets assume the developer wants to export everything in module "Utils". Then a seemingly elegant way to do this would be to put the following in the above-mentioned file "foo.mli":
module Utils : module type of Utils
But this has unintended consequences. If a user of library "Foo" now also defines a module "Utils" in their project, the compiler may complain that there are "inconsistent assumptions" about module "Utils".
The apparent reason is that "module type of Utils" in "foo.mli" is now being resolved using the "Utils" interface in the end user's project rather than the one in the library. This is a little strange, because if the end user doesn't define a "Utils" module, then the compiler will correctly refer to the "Utils" interface in the packed library - as intended.
I would say there is no scenario where it would make sense to interpret "module type of" in the above way. It's clear during packing what the referred to signature is.
A workaround for the library developer would be to just copy the whole signature of module "Utils" verbatim into "foo.mli", but this is obviously a cumbersome solution.
Could the semantics of name resolution in this scenario please be changed so that "module type of" refers to the correct context? Thanks!