Cannot import module that has name of a package

psp250 psp250 at sukimashita.com
Fri Mar 23 08:23:35 PDT 2007


Frits van Bommel Wrote:

> Hennrich Blöbaum wrote:
> > Hi!
> > 
> > Look at this:
> > 
> [snip]
> > 
> > This gives error:
> > test/foo.d: module test.foo module and package have the same name
> > 
> > 
> > Is there any reason why this is blocked?
> 
>  > <test/foo.d>
>  > module test.foo;
> 
> class bar {
>      static void baz() {
>          // ... Some function implementation ...
>      }
> }
> 
>  > <test/foo/bar.d>
>  > module test.foo.bar;
> 
> void baz() {
>      // ... Some completely different function implementation ...
> }
> 
>  > <main.d>
>  > import test.foo;
>  > import test.foo.bar;
> 
> void main() {
>      test.foo.bar.baz(); // which function does this call?
> }

Well, in D as well as other languages, such a file structure/example does not get past compilation and results in a symbol collision.

>From earlier experiments I know you could compile both modules individually and use a combined header file to attempt to link the object files which would give you a symbol collision error. As reports if you have no collision, it works.

So why can't D rather report such collisions at compile time or linking instead?

The current way in my point limits the way you can structure your D projects and is something which other languages do better. 

I think it could greatly enhance maintainability for D file hierarchies (and move it away from the currently really C-like module layouts).



More information about the Digitalmars-d mailing list