Pathological import symbol shadowing

Paul Backus snarwin at
Sat Nov 14 16:25:07 UTC 2020

On Saturday, 14 November 2020 at 15:48:47 UTC, Kagamin wrote:
> On Saturday, 14 November 2020 at 14:43:16 UTC, Paul Backus 
> wrote:
>> [1]
> Ah, ok.
> foo(1L);  // calls
> This line looks incorrect. If there was no foo(long), foo(1L) 
> would call foo(int), then if foo(long) appears, the call will 
> be silently diverted.

Yes, it is incorrect. In reality, it produces an error:

     Error: function at B.d(4) conflicts with function 
at A.d(3)

However, the reason for this is that the literal `1L` is treated 
as both an int and a long for the purposes of overload 
resolution, because the compiler can prove that its value will 
fit into both types. If you change it to a variable:

     long l;

...then is selected unambiguously, and removing it 
will cause an error  ("no overload matches") rather than calling

More information about the Digitalmars-d mailing list