August 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8564

           Summary: Ambiguous renamed import is allowed
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: maxim@maxim-fomin.ru


--- Comment #0 from Maxim Fomin <maxim@maxim-fomin.ru> 2012-08-20 03:32:46 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8564



--- Comment #1 from Maxim Fomin <maxim@maxim-fomin.ru> 2012-08-20 03:40:18 PDT ---
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".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------