Currently dmd accepts renamed import with local name,
which hijacks current module name and creates ambiguity.
in foo2.d:
module foo2;
import std.stdio;
void bar()
{
writeln("foo2");
}
in foo1.d:
module foo1;
import foo1 = foo2; //#1 hijack
import std.stdio;
void bar()
{
writeln("foo1");
}
int x;
void main()
{
foo1.bar(); // #2 ambiguous call is accepted
writeln(foo1.x); // #3, Error: undefined identifier 'x'
}
I think either #1 should be prohibited or #2 result in
"ambiguous call" error. Also, #3 should compile, because
x is defined in foo1.d
Comment #1 by maxim — 2012-08-20T03:40:18Z
Forgot to mention, "foo1.bar();" actually calls foo2.bar()
which I consider the biggest problem in this situation.
It is unlikely, that import hijack could be written in purpose,
but:
1) such situation can occur unintentionally, when programmer
renamed/moved file and forgot to update import line
2) foo1.bar() is actually foo2.bar() and this is very bad because
it contradicts to D approach "issue error if ambiguous function call is found".
Comment #2 by robert.schadek — 2024-12-13T18:01:09Z