Jonathan M Davis wrote:
> 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.
> 
        I'm not sure that the problem is on the line where the error is
reported. My guess would be that the issue is with the "auto a = new
Bar" line: I would bet that this gets interpreted as "Foo a = new
Bar" instead of what we expect ("Bar a = new Bar"). If I'm right,
then the "a = null" line is indeed an error: since Foo is a struct
and structs are value types, you cannot affect "null" to a variable
of type Foo...

                Jerome
-- 
mailto:jeber...@free.fr
http://jeberger.free.fr
Jabber: jeber...@jabber.fr

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to