Multiple alias this and alias this in classes

deadalnix deadalnix at gmail.com
Mon Jan 16 23:27:39 UTC 2023


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.


More information about the Digitalmars-d mailing list