www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - The module declaration is being ignored

reply "Diffuse" <diffuse mt2014.com> writes:
I have 2 files, main.d and file2.d.

In file2.d I have written at the top "module file2"
And in main.d I have written "import file2"

Everything works fine. But things also compile if I declare
file2's module to be "module candyfloss" while still importing
"file2" within main.d

In fact it doesn't work to import candyfloss within main.d, only
the exact name of the file works no matter the file's module
declaration.

I have confirmed that I am indeed editing the same files that I
am sending to dmd and the dmd version I am using is 2.066 which
is the newest on the website.

Is this normal?
Oct 08 2014
parent reply "Adam D. Ruppe via Digitalmars-d-learn" writes:
On Wed, Oct 08, 2014 at 06:39:26PM +0000, Diffuse via Digitalmars-d-learn wrote:
 Everything works fine. But things also compile if I declare
 file2's module to be "module candyfloss" while still importing
 "file2" within main.d
You should always import the same thing as the module, but you also need to pass the file to the compiler explicitly so it can find it. dmd main.d file2.d would work if you did import candyfloss; and module candyfloss; In general, I recommend always passing all files to the compiler explicitly so it can build an accurate file to module mapping and link all code in.
Oct 08 2014
parent reply "Diffuse" <diffuse mt2014.com> writes:
On Wednesday, 8 October 2014 at 18:46:38 UTC, Adam D. Ruppe via 
Digitalmars-d-learn wrote:
 On Wed, Oct 08, 2014 at 06:39:26PM +0000, Diffuse via 
 Digitalmars-d-learn wrote:
 In general, I recommend always passing all files to the 
 compiler explicitly
 so it can build an accurate file to module mapping and link all 
 code in.
My mistake. I am used to using dub and was having the exact same problem there so I decided to switch over to dmd to debug from there and I made this mistake. Do you know if dub sends all the files in the source dir of the package and its dependencies to dmd?
Oct 08 2014
parent "Diffuse" <diffuse mt2014.com> writes:
Okay I see what I'm doing wrong. While I can indeed declare a 
file's module to be whatever I like and in whatever package I 
like, this isn't going to work when that file is in a dub package 
that my program depends on because dub isn't sending those files 
to the compiler, they are only used for imports. So the only 
thing dub does is set the import path.
Oct 08 2014