Is this a compiler aliasing bug?

ag0aep6g anonymous at example.com
Fri Sep 17 10:22:25 UTC 2021


On 17.09.21 11:44, Chris Katko wrote:
> bool is_colliding_with(drawable_object_t obj) //was a class member
>      {
[...]
>      alias x2 = obj.x;
>      alias y2 = obj.y;
>      alias w2 = obj.w;
>      alias h2 = obj.h;
[...]
>          }

Those aliases don't work like you want them to. You can't have an alias 
to an object's field. What you get is an alias to the symbol in the 
class. I.e., you get this:

     alias x2 = typeof(obj).x;

And when you use that in a method, it becomes `this.x`. `obj` is 
completely forgotten.

I my opinion, `alias x2 = obj.x` should be an error, but I'm not sure if 
it's considered a bug.


More information about the Digitalmars-d-learn mailing list