www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Partially qualified module name lookup

reply Peter Alexander <peter.alexander.au gmail.com> writes:
If I have two functions within nested modules:

A.B.foo()
A.C.foo()

Why can't I refer to them using

B.foo();
C.foo();

??

DMD just complains about undefined identifiers B and C.

The only way to refer to those is to fully qualify them:

A.B.foo();
A.C.foo();

Is this a bug?
Feb 15 2011
parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
If modules B and C belong to the A package, then there are no "B" and
"C" modules, there are "A.B" and "A.C" modules. You can refer to a foo
function by either:
foo()
or
A.b.foo()

Of course, in this case the two functions will conflict if you don't
fully qualify the names. A workaround is to use named imports:

import B = A.B;
import C = A.C;

void main()
{
    B.foo();
    C.foo();
}
Feb 15 2011