DIP66 - Multiple alias this

IgorStepanov via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 10 16:25:35 PDT 2014


On Friday, 10 October 2014 at 22:51:34 UTC, Walter Bright wrote:
> On 10/10/2014 3:46 PM, Timon Gehr wrote:
>> On 10/11/2014 12:29 AM, Walter Bright wrote:
>>> On 10/10/2014 3:06 PM, Timon Gehr wrote:
>>>> On 10/10/2014 11:25 PM, Walter Bright wrote:
>>>>>
>>>>> Essentially, the rules for multiple alias this should be 
>>>>> the same as for
>>>>> multiple imports and multiple mixin templates. These rules 
>>>>> work, and the
>>>>> consistency will be expected.
>>>>
>>>> Agreed. Do you suggest to overload alias this against 
>>>> imports and
>>>> mixin templates?
>>>
>>> I hadn't thought of that (thanks for bringing it up). My 
>>> first thought
>>> is no. Alias this gets searched after those do, because it 
>>> comes into
>>> play only when the symbol isn't resolved in the scope.
>>
>> This allows for symbol hijacking (this is also the current 
>> behaviour):
>>
>> // ---
>>
>> module m;
>> import std.stdio;
>> // void foo(int x){ writeln("hi from m"); } // uncomment to 
>> hijack
>>
>> // ---
>>
>> module main;
>> import std.stdio;
>>
>> struct T{
>>     import m;
>>     alias s this;
>>     S s;
>> }
>>
>>
>> struct S{
>>     void foo(int x){ writeln("hi from S"); }
>> }
>>
>> void main(){
>>     T t;
>>     t.foo(1);
>> }
>
> Hmm. Good point. The alias this should be done before imports.

Symmetrically. You may use symbol from import, uncomment it in 
aliased type and hijack it.


More information about the Digitalmars-d mailing list