local import hijacking

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 14 08:09:29 PST 2016


On 01/14/2016 10:17 AM, anonymous wrote:
> On 14.01.2016 15:25, Byron Heads wrote:
>> I got burned by this yesterday, this code should not compile
>>
>> import std.experimental.logger : trace;
>>
>>
>> void foo() {
>>      import std.net.curl : trace;
>>      trace("hello");
>> }
>>
>>
>> void main() {
>>      foo();
>> }
>
> I don't see a problem with that specific code. You're explicitly
> importing `trace` from std.net.curl, so it can't be surprising that it's
> called.
>
> But change one little detail and this qualifies as hijacking, I think:
>
> ----
> void foo() {
>      import std.net.curl; /* not mentioning trace */
>      trace("hello");
> }
> ----
>
> Imagine that std.net.curl didn't have a `trace` function when the code
> was written. std.experimental.logger.trace would have been called then.
> When a `trace` function is then added to std.net.curl, the code suddenly
> calls a different `trace`, without any warning. Hijacking.

Yes, this needs to be fixed. -- Andrei



More information about the Digitalmars-d mailing list