www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17589] New: Prevent local imports from hiding imported symbols

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 puremagic.com
          Reporter: timon.gehr 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.

--
Jul 03