www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Possibile import problem

reply bearophile <bearophileHUGS lycos.com> writes:
This is a problem I have found, it requires 3 source files, called test.d, a.d,
b.d.

---------------

The a.d module:

import std.string: join;
import std.string: join;

---------------

The b.d module: 

import std.string: join;

---------------

The main module is test.d:

import a, b;
void main() {
    join(["a"], "");
}

---------------

DMD v1.024 produces this:

test.d(4): Error: a.join at a.d(1) conflicts with b.join at b.d(1)

Is this a bug? Aren't names qualified imports private too? And if not, why?

Bye,
bearophile
Dec 17 2007
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
bearophile wrote:
 This is a problem I have found, it requires 3 source files, called test.d,
a.d, b.d.
 
 ---------------
 
 The a.d module:
 
 import std.string: join;
 import std.string: join;
 
 ---------------
 
 The b.d module: 
 
 import std.string: join;
 
 ---------------
 
 The main module is test.d:
 
 import a, b;
 void main() {
     join(["a"], "");
 }
 
 ---------------
 
 DMD v1.024 produces this:
 
 test.d(4): Error: a.join at a.d(1) conflicts with b.join at b.d(1)
 
 Is this a bug? Aren't names qualified imports private too? And if not, why?

Yes, they should be private. The fact that they aren't is a bug. One of these: http://d.puremagic.com/issues/show_bug.cgi?id=313 http://d.puremagic.com/issues/show_bug.cgi?id=314 http://d.puremagic.com/issues/show_bug.cgi?id=1238 http://d.puremagic.com/issues/show_bug.cgi?id=1504 This is total guess, but I suspect the reason is because selective imports are just a quick hack that change the import to a static import and then do an alias for you. In other words I'm pretty sure this: import module : identifier; generates code identical to this: static import module; alias module.identifier identifier; I'm not sure why it wouldn't turn it into "private alias", but I think one of those bugs above says private aliases still conflict, so maybe it *is* actually turning it into a private alias. --bb
Dec 17 2007