[Issue 17589] New: Prevent local imports from hiding imported symbols

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jul 3 13:18:31 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17589

          Issue ID: 17589
           Summary: Prevent local imports from hiding imported symbols
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: timon.gehr at gmx.ch

As issue 10378 has been closed even though problems remain, I'm opening a new
issue.

The following code demonstrates a hijacking problem in the current local import
lookup rules:

import std.stdio;

string readAndLog(string filename){
    import std.file;
    auto text=readText(filename);
    write(filename," read successfully!\n");
    return text;
}

void main(){
    writeln(readAndLog("important_data.txt"));
}

Upon execution, this code will delete the important data.

Local imports should overload against less deeply nested imports. In this
example, std.stdio.write and std.file.write should be treated as part of the
same overload set within readAndLog. Otherwise, there is a hijacking risk.

--


More information about the Digitalmars-d-bugs mailing list