Bug 5669 – Constructor calls should be valid inside final switch

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-02-28T12:34:13Z
Last change time
2024-12-13T17:54:54Z
Assigned to
No Owner
Creator
Don
Moved to GitHub: dmd#18331 →

Comments

Comment #0 by clugdbug — 2011-02-28T12:34:13Z
Posted on behalf of Mafi ---- http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=130643 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 ridiculous. I mean it's an assert(0) which is statically known to fail. It should check if all paths call constructors or _fail_
Comment #1 by lt.infiltrator — 2015-12-09T11:44:41Z
The first example still fails to compile with messages about constructors behind labels. The second compiles with 2.069 though.
Comment #2 by dmitry.olsh — 2018-05-22T14:59:19Z
Still fails talking about jumps on 2.080 enum SomeEnum { A, B} class D { this(int); this(string); this(SomeEnum s) { final switch(s) { case SomeEnum.A: this("Hello"); break; case SomeEnum.B: this(3); break; } } }
Comment #3 by robert.schadek — 2024-12-13T17:54:54Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18331 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB