Comment #0 by sigurdbergsvela — 2015-06-11T14:58:29Z
Created attachment 1527
Minimalistic example
I have a structure
src
|-> main.d
|-> RootClass.d
|-> MyPackage/
|-> PackagedClass.d
If I add an import in *RootClass* to *myPackage.PackagedClass*, it's fine.
If I remove that import, and an import to *PackagedClass* to *RootClass*, it fine.
But with both, I get an error form DMD saying:
"../src/RootClass.d(1): Error: module PackagedClass from file ../src/myPackage/PackagedClass.d must be imported with 'import PackagedClass;'"
I'v included a minimalistic example. While creating the example I noticed that this issue did not appear if both *RootClass* and *PackagedClass* was in the same directory/package.
Comment #1 by dlang-bugzilla — 2015-06-11T21:59:20Z
I'm fairly sure this is an invalid bug. Modules inside packages must have a module declaration. The fix is to add `module myPackage.PackagedClass;` at the top of myPackage/PackagedClass.d.
Comment #2 by sigurdbergsvela — 2015-06-12T01:02:29Z
I that case, It's very weird that it would work in the case where you remove one of the import in my example, and a fairly odd error message.
Comment #3 by dlang-bugzilla — 2017-07-03T20:07:23Z
(In reply to sigsve from comment #0)
> I have a structure
> src
> |-> main.d
> |-> RootClass.d
> |-> MyPackage/
> |-> PackagedClass.d
>
> If I add an import in *RootClass* to *myPackage.PackagedClass*, it's fine.
This only works when you compile one file at a time, so the compiler does not notice the module name discrepancy. The way you build your project is very unusual, today most D software is built with dub or rdmd.
In short: the compiler is not detecting a problem in your project as an optimization. When dealing with packages, all modules need to have a module statement indicating the full name of the module - even if you don't do that and somehow get things to compile, you will likely get linking errors due to differences in full mangled names of symbols.