Multiple alias this and alias this in classes

12345swordy alexanderheistermann at gmail.com
Tue Jan 17 18:16:09 UTC 2023


On Monday, 16 January 2023 at 23:27:39 UTC, deadalnix wrote:
> During a recent discussion with several D folks, several 
> people, including Walter told ma that the situation with 
> multiple alias this and alias this in classes was hopelessly 
> broken. I suggested it needed to be either fixed or removed.
>
> However, during this discussion, I took the fact it was 
> hopelessly broken for granted. But it doesn't appear to me that 
> this is obvious. Can someone familiar with the topic care to 
> explain or point me to a link where this case was made already?
>
> On an asside, I implemented both multiple alias this and alias 
> this for classes in SDC. Because these feature were never 
> completed in DMD, I had to extrapolate to figure out what the 
> semantic should be, and this is what I came up with.
>
> 1/ Alias this is used in two contextes: casts and identifier 
> resolution.
> 2/ For struct, it just follow the expected rule for cast and 
> resolution, if these rule succeed, then nothing more happen. If 
> they fail, then the operation is repeated again with all the 
> declared alias this. If the number of valid result is 1 and 
> exactly 1, then it is used. If the number of valid result is 0 
> or greater than 1, then an error is emitted.
> 3/ For classes, lookups ignore alias this and walk up the 
> parent stack, still ignoring any alias this. If that fails, 
> then all the alias this from this class and its parent are run 
> at once, and if the number of valid result is 1, then this is 
> fine, if it is 0 or greater than 1, then an error is emitted. 
> The same is done for casts.
>
> I think this semantic is reasonable. But I have to say I did 
> not put a ton of though into it, so maybe there is a big fatal 
> flaw I'm overlooking.

We don't need alias this for classes, we just need custom 
implicit conversion for structs and classes. Other OOP languages 
have them, yet it from the cpp world that I keep hearing 
complaints regarding implicit conversions.

- Alex


More information about the Digitalmars-d mailing list