Multiple alias this, what's the hold up?

Timon Gehr timon.gehr at gmx.ch
Sun Jun 16 14:23:37 UTC 2019


On 16.06.19 08:19, Jonathan Marler wrote:
> On Sunday, 16 June 2019 at 01:21:16 UTC, Timon Gehr wrote:
>> On 16.06.19 03:04, Jonathan Marler wrote:
>>> On Saturday, 15 June 2019 at 23:30:09 UTC, 12345swordy wrote:
>>>> On Saturday, 15 June 2019 at 10:12:46 UTC, Amex wrote:
>>>>> How many years has it been in limbo? 1? 2? 3? 5? 10?
>>>>>
>>>>> What is the hold up?
>>>>
>>>> What the hold up is that walter thinks it is a bad idea to implement 
>>>> multiple alias this as he think it results in a multiple inheritance 
>>>> problem. There has been recent discussion regarding deprecating 
>>>> alias this.
>>>
>>> Maybe we could add it as an optional feature enabled with a 
>>> command-line option?
>>>
>>> I think there's a command line format for features like this 
>>> "-feature=miltialias" or something.
>>> ...
>>
>> That probably won't fly.
>>
>>> That way if there really are issues we could demonstrate them and 
>>> remove the feature later, or if no issues are found it could be 
>>> enabled by default.
>>
>> In terms of lookup, the issues with multiple alias this are the same 
>> as the issues with multiple import declarations. Implicit conversions 
>> could use the same lookup rules, but there would need to be a way to 
>> disambiguate. The code in the compiler that implements import 
>> declarations is unlikely to be easily reusable.
> 
> Having a hard time trying to figure out what you mean here.  I'm not 
> sure what you mean by "multiple import declarations".  Is this what you 
> mean?
> 
> import std.stdio;
> import std.stdio;
> 
> Or maybe this?
> 
> import std.stdio;
> void foo()
> {
>      import std.stdio;
> }
> 
> Then you said "Implicit conversions could use the same lookup rules", 
> but I'm not sure what you're saying there either.  Maybe if I understood 
> what you meant my "import declarations" then it would make sense?
> ...

Probably. What I mean is multiple imports of different modules:

import std.file;
import std.stdio;

void main(){
     write("hello","world"); // error: ambiguous
}

This is the same situation as:

struct S{
     void write(T...)(string file,T args){ ... }
}
struct T{
     void write(T...)(T args){ ... }
}

struct U{
     S s;
     T t;
     alias s this;
     alias t this;
}

void main(){
     U u;
     u.write("hello","world"); // error: ambiguous
}

Basically any complaint against multiple `alias this` can be turned into 
a complaint against multiple imports, and all the solutions already 
exist in D's module system.


More information about the Digitalmars-d mailing list