Anonymous nested class of problems

Tomek Sowiński just at ask.me
Sat Dec 12 15:56:06 PST 2009


Dnia 13-12-2009 o 00:44:56 Tomek Sowiński <just at ask.me> napisał(a):

> Dnia 12-12-2009 o 13:09:49 Tomek Sowiński <just at ask.me> napisał(a):
>
>> But that's not all, when I mark my class immutable...
>>
>> immutable class M {
>>      this(byte a) { _a = a; }
>>      byte _a;
>>      byte a() { return _a; };
>> }
>>
>> void main() {
>>      auto m = new class(4) M {
>>          this(byte a) { super(a); }
>>          override byte a() { return 3+_a; }
>>      };
>> }
>>
>> ... the compiler says: cannot implicitly convert expression (this) of  
>> type immutable(M) to test.M.
>> Same story for const classes. Again, compiler bug?
>
> It's not only about anonymous classes. Take a look at this:
>
> immutable class M {
>      this(int a) { _a = a; }
>      int _a;
>      int a() { return _a; }
> }
>
> immutable class PodM : M {
>      this(int a) { super(a); }
>      override int a() { return 3+_a; }
> }
>
> void main() {
>      auto m = new PodM(3);
> }
>
> The above still throws the same error:
> Error: cannot implicitly convert expression (this) of type immutable(M)  
> to test.M
> Error: cannot implicitly convert expression (this) of type  
> immutable(PodM) to test.PodM
>
> Compiler bug I guess...

Should've DAFS first...
http://d.puremagic.com/issues/show_bug.cgi?id=2610
What's disturbing is that this bug is nearly a year old... Could this be  
that immutable classes lay there virtually unusable for so long?


Tomek


More information about the Digitalmars-d-learn mailing list