Bug 16071 – Source file path and module name should match exactly

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-05-24T20:34:00Z
Last change time
2016-10-14T15:49:59Z
Assigned to
nobody
Creator
pro.mathias.lang

Comments

Comment #0 by pro.mathias.lang — 2016-05-24T20:34:16Z
Extract from https://dlang.org/spec/module.html : ``` The Identifiers preceding the rightmost are the Packages that the module is in. The packages correspond to directory names in the source file path. Package names cannot be keywords, hence the corresponding directory names cannot be keywords, either. ``` According to this definition, one cannot use a different name for the enclosing directory, nor can one introduce virtual package namespace, e.g. : src/foo/bar.d -> module hello.world.bar; However this is currently allowed. Using this kind of scheme breaks separated compilation badly, as the compiler rely on the module name for import. However, if the module is provided via command line, the compiler will first 'importAll', and the bug won't be visible. Even worst, the module declaration is ignored and the path is preferred in some cases, not others: ---- Import using the path ---- `src/main.d -> module main; import foo.bar;` Separate compilation: `dmd -c -o- -Isrc src/main.d` => Works All at once : `dmd -c -o- src/main.d src/foo/bar.d` => Doesn't work ---- Import using the given name ---- `src/main.d -> module main; import hello.world.bar;` Separate compilation: `dmd -c -o- -Isrc src/main.d` => Doesn't work All at once : `dmd -c -o- src/main.d src/foo/bar.d` => Works In addition, the specs provides the possibility to rename a file name with an invalid identifier (e.g. `foo-bar.d` -> `module foo_bar;`), and that suffers from the same problems. Even DMD is affected by this, as files are e.g. `src/mars.d` but the module name is `ddmd.mars`.
Comment #1 by bugzilla — 2016-09-19T10:06:48Z
The purpose for it being overridden is so that one can temporarily "swap in" an alternate version of a source file from another directory. This is very useful in debugging thinks like Phobos. It's a feature not a bug. I plan to fix dmd so that its imports match its file structure, for the reasons you mentioned. Anyhow, this is working as designed, and is a feature.
Comment #2 by mathias.lang — 2016-09-19T10:24:43Z
Thanks for the rationale, and glad to hear you're planning to fix it in DMD! We should probably document it at some point, but it's a minor point.
Comment #3 by mathias.lang — 2016-10-14T15:49:59Z
*** Issue 9194 has been marked as a duplicate of this issue. ***