Thread overview
Cannot import module that has name of a package
Mar 22, 2007
Hennrich Blöbaum
Mar 22, 2007
Frits van Bommel
Mar 22, 2007
Hennrich Blöbaum
Mar 22, 2007
J Duncan
Mar 22, 2007
Hennrich Blöbaum
Mar 23, 2007
Don Clugston
March 22, 2007
Hi!

Look at this:

<main.d>
import test.foo;
import test.foo.bar;

<test/foo.d>
module test.foo;

<test/foo/bar.d>
module test.foo.bar;


This gives error:
test/foo.d: module test.foo module and package have the same name


Is there any reason why this is blocked?


Hennrich
March 22, 2007
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?
}
March 22, 2007

Hennrich Blöbaum wrote:
> Hi!
> 
> Look at this:
> 
> <main.d>
> import test.foo;
> import test.foo.bar;
> 
> <test/foo.d>
> module test.foo;
> 
> <test/foo/bar.d>
> module test.foo.bar;
> 
> 
> This gives error:
> test/foo.d: module test.foo module and package have the same name
> 
> 
> Is there any reason why this is blocked?
> 
> 
> Hennrich

Because its illegal, you could have FQNs that are unable to resolve....

I get around this by using uppercase (or camel case) for module names.

module test.Foo;

 - and -

module test.foo.Bar;


this is a violation of walters suggested style guide, and it will not compile on operating systems that force a single case. But I happen to love the practice, as now I am able to reuse package names for module names.
March 22, 2007
Frits van Bommel schrieb:
> 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?
> }

oh yeah... ;)

thanks
March 22, 2007
J Duncan schrieb:
> 
> 
> Hennrich Blöbaum wrote:
>> Hi!
>>
>> Look at this:
>>
>> <main.d>
>> import test.foo;
>> import test.foo.bar;
>>
>> <test/foo.d>
>> module test.foo;
>>
>> <test/foo/bar.d>
>> module test.foo.bar;
>>
>>
>> This gives error:
>> test/foo.d: module test.foo module and package have the same name
>>
>>
>> Is there any reason why this is blocked?
>>
>>
>> Hennrich
> 
> Because its illegal, you could have FQNs that are unable to resolve....
> 
> I get around this by using uppercase (or camel case) for module names.
> 
> module test.Foo;
> 
>  - and -
> 
> module test.foo.Bar;
> 
> 
> this is a violation of walters suggested style guide, and it will not compile on operating systems that force a single case. But I happen to love the practice, as now I am able to reuse package names for module names.

Yes, I have seen this, but as style guide says, windows is sadly ignored.
March 22, 2007
Hennrich Blöbaum wrote:
> J Duncan schrieb:
>>
>>
>> Hennrich Blöbaum wrote:
>>> Hi!
>>>
>>> Look at this:
>>>
>>> <main.d>
>>> import test.foo;
>>> import test.foo.bar;
>>>
>>> <test/foo.d>
>>> module test.foo;
>>>
>>> <test/foo/bar.d>
>>> module test.foo.bar;
>>>
>>>
>>> This gives error:
>>> test/foo.d: module test.foo module and package have the same name
>>>
>>>
>>> Is there any reason why this is blocked?
>>>
>>>
>>> Hennrich
>>
>> Because its illegal, you could have FQNs that are unable to resolve....
>>
>> I get around this by using uppercase (or camel case) for module names.
>>
>> module test.Foo;
>>
>>  - and -
>>
>> module test.foo.Bar;
>>
>>
>> this is a violation of walters suggested style guide, and it will not compile on operating systems that force a single case. But I happen to love the practice, as now I am able to reuse package names for module names.
> 
> Yes, I have seen this, but as style guide says, windows is sadly ignored.

The near alternative is to have packages /contain/ a module by the same name.

module test.foo.Foo ;
module test.bar.Bar ;

It has always felt really awkward to me, though.

-- Chris Nicholson-Sauls
March 23, 2007
Hennrich Blöbaum wrote:
>> I get around this by using uppercase (or camel case) for module names.
>>
>> module test.Foo;
>>
>>  - and -
>>
>> module test.foo.Bar;
>>
>>
>> this is a violation of walters suggested style guide, and it will not compile on operating systems that force a single case.
Such as?

> But I happen to 
>> love the practice, as now I am able to reuse package names for module names.
> 
> Yes, I have seen this, but as style guide says, windows is sadly ignored.
It works fine on Windows. As long as D is case-sensitive, it will work even if the OS is case-insensitive. You just need a module statement so that D knows what the correct case-sensitive name is. And when creating the file, you need to use the correct capitalisation so that it will work on case-sensitive OSes.