Cannot import module that has name of a package

Chris Nicholson-Sauls ibisbasenji at gmail.com
Thu Mar 22 12:15:55 PDT 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



More information about the Digitalmars-d mailing list