DIP66 - Multiple alias this

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 10 15:46:29 PDT 2014


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);
}


More information about the Digitalmars-d mailing list