[Issue 453] When importing modules compiler can not distinguish between directory and file

Bradley Smith user at domain.invalid
Wed Oct 25 18:02:38 PDT 2006


Walter Bright wrote:
> d-bugmail at puremagic.com wrote:
>> Can't packages be distinguished from modules?
> 
> Consider the following:
> 
>     int F;
>     class F { }
> 
> That doesn't work either. Cannot have two identical names in the same 
> scope mean different things.
> 
> Now consider:
> 
>     import name;        // name.d
>     import name.foo;    // name\foo.d
> 
> and in the code:
> 
>     name.foo.bar;
> 
> is that foo.bar inside name.d, or bar inside name\foo.d? It's not going 
> to work.

I see your point. From my point of view, this is simply another case of 
symbols conflicting, similar to symbols with the same name imported from 
different modules. When that happens, the compiler reports the problem, 
and I have to resolve it. Couldn't the compiler look for name.foo.bar in 
both name.d and name\foo.d, and report an ambiguity if one exists? For 
example:

dmd main.d name.d name\foo.d
main.d(6): Error: name.foo.bar has multiple definitions: foo.bar in 
name.d(4), and bar in name\foo.d(2)

----- name.d -----
struct F {
   int bar = 1;
}
F foo;

----- name\foo.d -----

int bar = 2;

----- main.d -----

import name;
import name.foo;

void main() {
   printf(name.foo.bar);
}



More information about the Digitalmars-d-bugs mailing list