Complicated Types: Prefer “alias this” Over “alias” For Easier-To-Read Error Messages

Simen Kjærås simen.kjaras at gmail.com
Mon May 21 17:05:53 UTC 2018


On Monday, 21 May 2018 at 14:48:23 UTC, Mike Parker wrote:
> Nick Sabaluasky's first post to the D Blog is a tip on how to 
> create an aliased type that keeps its name in error messages.

Nice. Interestingly, the error message references the wrong type 
when trying to access static members:

struct MT {
     int _payload;
     alias _payload this;
}

unittest {
     MT a;
     a.foo = 3;  // Error: no property foo for type MT
     MT.foo = 3; // Error: no property foo for type int
}

https://issues.dlang.org/show_bug.cgi?id=18892

--
   Simen


More information about the Digitalmars-d-announce mailing list