www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Constructor-calls

reply Mafi <mafi example.org> writes:
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
Feb 25 2011
parent reply Peter Alexander <peter.alexander.au gmail.com> writes:
On 25/02/11 4:24 PM, Mafi wrote:
 Hi all,
...
 Mafi
Submit an enhancement request.
Feb 25 2011
parent reply Mafi <mafi example.org> writes:
Am 25.02.2011 20:01, schrieb Peter Alexander:
 On 25/02/11 4:24 PM, Mafi wrote:
 Hi all,
 ...
 Mafi
Submit an enhancement request.
I'll do when I find time!
Feb 26 2011
parent Don <nospam nospam.com> writes:
Mafi wrote:
 Am 25.02.2011 20:01, schrieb Peter Alexander:
 On 25/02/11 4:24 PM, Mafi wrote:
 Hi all,
 ...
 Mafi
Submit an enhancement request.
I'll do when I find time!
I've done it for you. http://d.puremagic.com/issues/show_bug.cgi?id=5669
Feb 28 2011