Why the compiler dosen't enforce correct module declarations?

Ary Manzana ary at esperanto.org.ar
Sat May 12 09:51:33 PDT 2007


I can have three files:

main.d:
---
module one;

import two;
import lala.la;

void main() {
    foo();
    bar();
}
---

other.d
---
module two;

import std.stdio;

void foo() {
    writefln("Hello!");
}
---

dir/some_other.d
---
module lala.la;

import std.stdio;

void bar() {
    writefln("Hello!!");
}
---

and compile them with no problem:
dmd main.d other.d dir/some_other.d

Shouldn't the compiler say "Wait, you are saying that module one is in 
file main.d, module two is in other.d and module lala.la is in 
dir/some_other.d, this isn't quite well"? In 
http://www.digitalmars.com/d/module.html it states:

"The packages correspond to directory names in the source file path."
"The module name is the file name with the path and extension stripped off."

Why this isn't honored by the compiler?

My worry is, if this is valid, then in an IDE you can't just assume 
directories are packages, and filenames (path and extension stripped 
off) are modules, since this is not mandatory. Then it's a lot harder to 
do. Further, it complicates things since probably nobody wants to name a 
module with a name and path that dosen't match the underlying 
filesystem's name and path. So enforcing this in a compiler eliminates 
"bugs".


More information about the Digitalmars-d-learn mailing list