[Issue 10378] Local imports hide local symbols
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Thu Aug 28 00:12:18 PDT 2014
    
    
  
https://issues.dlang.org/show_bug.cgi?id=10378
dbr <dbugreporter at gmail.com> changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dbugreporter at gmail.com
--- Comment #3 from dbr <dbugreporter at gmail.com> ---
The fact that local imports hide things instead of properly detecting conflicts
is a dangerous bug. I actually almost trashed a bunch of files because of it
since I had something like this:
import std.stdio;
void main() {
    import std.file;    // just wanted to use dirEntries!
    auto files = dirEntries("importantfiles", "*.{png}", SpanMode.depth);
    foreach (f; files) {
        auto hdr = read_header(f.name);
        writeln(f.name, ":");
        writefln("%d x %d", hdr.width, hdr.height);
    }
}
Luckily, I had that read_header call *after* the first writeln, and it of
course threw and I only lost one file (and it wasn't actually important). I
know (now!) that the docs say this about local (or "scoped") imports: "Imported
symbols may hide symbols from outer scopes", but this is damn insane. It's
inconsistent and surprising.
--
    
    
More information about the Digitalmars-d-bugs
mailing list