Hi all,

dmd gets on my nerves with constructor-calls.
First I tried the following which dmd complains about.

enum SomeEnum { A, B}

class D : C {
        this(int);
        this(string);
        
        this(SomeEnum s) {
                final switch(s) {
                        case SomeEnum.A: this("Hello"); break;
                        case SomeEnum.B: this(3); break;
                }
        }
}

dmd says it's not valid because constructor-calls are not valid behind labels. But these labels are the cases of a final switch with no gotos in it. IMO my code is perfectly valid and dmd should see it. It shouldn't be too complicated check because final switch already enforces breaks and that all possible paths a defined. Just check if it's final switch and there are no 'goto case's in there.

class D : C {
        this(int);
        this(string);

        this(SomeEnum s) {
                if(s == SomeEnum.A) {
                        this("Hello");
                } else if(s == SomeEnum.B) {
                        this(3);
                } else assert(0);
        }
}

It says now that one path does not have constructor-call. This is ridicolous. I mean it's an assert(0) which is statically known to fail.
It should check if all paths call constructors or _fail_ IMO.

Mafi

Reply via email to