unittest compiles w/o error though module file is not named after the module

Adam D. Ruppe destructionator at gmail.com
Sat Feb 6 14:52:57 UTC 2021


Module names and file names are completely independent on the 
language level. You can have a file `whatever.d` with `module 
foo.bar.totally.different;` and `import 
foo.bar.totally.different` and it all works as long as you add 
the whatever.d to the build.

The only reason people recommend they match is that then the file 
can be found automatically.

dmd program.d whatever.d # works from module names

dmd -i program.d # now it will look for 
foo/bar/totally/different.d by convention because you didn't list 
the file.


That one `import p;` is kinda weird, it should probably complain 
then you imported one thing and got another, but generally the 
name not matching is no problem at all.


More information about the Digitalmars-d-learn mailing list