Fighting with alias this: bugs or features?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Oct 26 10:28:38 PDT 2010
On Tuesday, October 26, 2010 09:35:21 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...
If you can't find a bug report for it, report it. I don't see how it could
possibly be a feature that null couldn't be converted. Any pointer or reference
type should be assignable to null. And in general, it's probably better to
report a bug if you're not sure. If it's not valid, it'll get closed, but odds
are that it's something that needs to be fixed.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list