Are aliases supossed to be implicitly cross-module overloadable?

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Aug 22 10:22:00 PDT 2010


Interestingly, a public import *does* work:

module1.d:
void foo(double)
{
}

module2.d:
public import module3;

void foo(string)
{
}

module3.d:
void foo(int[])
{
}

main.d:
import module1, module2;

void main()
{
    foo(5.5);
}

Compiles fine and runs fine. And according to TDPL, a public import is
a shorthand for an alias for every symbol found in the imported
module. So my guess is there's some kind of bug with aliasing.

On Sun, Aug 22, 2010 at 6:48 PM, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> I understand the situtation when functions from two modules compete
> over a call and both are eligible for the call. In that case it's an
> error (since the compiler protects against function hijacking). But in
> this case, only the function from the first module is eligible for the
> call.
>
> Let me do a simple comparison to make this easier to see:
>
> module1.d:
> void foo(double)
> {
> }
>
> module2.d:
> void foo(string)
> {
> }
>
> module3.d:
> void foo(int[])
> {
> }
>
> main.d:
> import module1, module2, module3;
>
> void main()
> {
>    foo(5.5);
> }
>
> This works fine. The functions cannot hijack each other.
>
> Now I'll remove the import to module3 in main.d, and instead import
> module3 from module2 and use an alias. The files are now:
>
> module1.d:
> void foo(double)
> {
> }
>
> module2.d:
> import module3;
> alias module3.foo foo;
>
> void foo(string)
> {
> }
>
> module3.d:
> void foo(int[])
> {
> }
>
> main.d:
> import module1, module2;
>
> void main()
> {
>    foo(5.5);
> }
>
> But now I have a conflict:
> main.d(5): Error: module1.foo at module1.d(1) conflicts with
> module2.foo at module2.d(2)
>
> Even though the functions still can't hijack each other, adding an
> alias in a module seems to break compilation.
>
> And the way to fix this, is that I need to explicitly add aliases to
> the functions in main.d:
>
> import module1, module2;
>
> alias module1.foo foo;
> alias module2.foo foo;
>
> void main()
> {
>    foo(5.5);
> }
>
> So, are the aliases really needed here? Shouldn't the compiler be able
> to figure out that the functions from module1.d and module2.d never
> hijack each other if there's an alias in one of the modules?
>
> On Sat, Aug 21, 2010 at 6:59 PM, Andrej Mitrovic
> <andrej.mitrovich at gmail.com> wrote:
>> snip
>


More information about the Digitalmars-d mailing list