I was playing with what makes the Javists proud, but stumbled over this:

class M {
    this(byte a) { _a = a; }
    byte _a;
    byte a() { return _a; };

    static m = new class(4) M {
        this(byte a) { super(a); }
        override byte a() { return 3+_a; }
    };
}

Error: class test.M.__anonclass10 has forward references
Error: no constructor for __anonclass10

Is this a compiler bug? There's no reason why the above shouldn't compile, no?


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?


Tomek

Reply via email to