Pathological import symbol shadowing

Timon Gehr timon.gehr at gmx.ch
Sun Nov 22 01:45:00 UTC 2020


On 21.11.20 03:25, Walter Bright wrote:
>>>
>>
>> It's a prototypical example of symbol hijacking. std.file.write hides 
>> std.stdio.write. Therefore, the code above overwrites the contents of 
>> the file "important_data.txt" with the string " read sucessfully!\n". 
>> The code should result in an ambiguity error as there are matches in 
>> two distinct overload sets.
> 
> That isn't hijacking, it's scoping. Hijacking is when an overload is 
> added to one module that is accidentally a better match than unrelated 
> overloads in another module, when both are in the same scope.

You can have three modules where module `A` imports module `B` and `C` 
and if I add a symbol `foo` in module C, some lookup in `A` changes from 
`B.foo` to `C.foo`. I'd call that hijacking: You have a relationship 
between modules `A` and `B` that is intruded upon by some unrelated 
change in module `C`. (Anyway, my point was actually that this is bad, 
not that it should be called hijacking. It's even bad for the same 
reason "overload" hijacking is bad.)


More information about the Digitalmars-d mailing list