Dnia 12-12-2009 o 13:09:49 Tomek Sowiński <[email protected]> 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...


Tomek

Reply via email to