[Issue 16071] New: Source file path and module name should match exactly
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue May 24 13:34:16 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16071
Issue ID: 16071
Summary: Source file path and module name should match exactly
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: pro.mathias.lang at gmail.com
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`.
--
More information about the Digitalmars-d-bugs
mailing list