On Saturday, 15 June 2013 at 15:29:23 UTC, Mr. Anonymous wrote:
On Saturday, 15 June 2013 at 15:09:55 UTC, Peter Alexander wrote:
On Saturday, 15 June 2013 at 12:20:46 UTC, Timon Gehr wrote:
One issue with local imports is that they hide local symbols.

Can you give an example? I can't repro.

void main()
{
        import std.stdio;
        void writeln(string) {}
        writeln("foo");
        std.stdio.writeln("bar");
}

This writes only "bar".

void writeln(string) {}
void main()
{
        import std.stdio;
        writeln("foo");
        std.stdio.writeln("bar");
}

Oh, but that's not a local symbol, that's a module level symbol. The import is more local that the module level writeln, so that works as you would expect.

It also isn't a problem at all, because you can easily refer to the module level symbol by fully qualifying it.

module thismodule;
void writeln(string) {}
void main()
{
        import std.stdio;
        thismodule.writeln("foo");
        std.stdio.writeln("bar");
}

In any case, I'd recommend explicitly choosing which symbols to import in the local import to avoid name clashes.

Reply via email to