Fighting with alias this: bugs or features?
Steven Schveighoffer
schveiguy at yahoo.com
Wed Oct 27 17:19:57 PDT 2010
On Tue, 26 Oct 2010 12:35:21 -0400, osa <osa at aso.osa> wrote:
> Every time I'm trying to use alias this (which looks like a nice
> feature, on paper), I end up with problems. This is the most recent one
> (dmd v2.049):
> ------
> struct Foo {}
> class Bar {
> Foo foo_;
> alias foo_ this;
> }
>
> void main() {
> auto a = new Bar;
> auto b = a;
> a = null; // fails -- Error: cannot implicitly convert expression
> (null) of type void* to Foo
> }
> ------
> There are plenty of 'alias this' issues in Bugzilla, but I cannot find
> this particular problem there. So is this a bug or feature? The language
> spec does not help do decide...
alias this seems to favor the aliased member over the container itself in
many cases. I'm not sure why. Alias this should be used as the last
resort IMO, because when you are aliasing this, you don't want the aliased
member forcefully taking control of your object.
I recently filed this bug report, which has a similar feel to your
problem: http://d.puremagic.com/issues/show_bug.cgi?id=4989
I think there may be others that are similar.
-Steve
More information about the Digitalmars-d
mailing list