www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5669] New: Constructor calls should be valid inside final switch


           Summary: Constructor calls should be valid inside final switch
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: clugdbug yahoo.com.au

--- Comment #0 from Don <clugdbug yahoo.com.au> 2011-02-28 12:34:13 PST ---
Posted on behalf of Mafi

First I tried the following which dmd complains about.

enum SomeEnum { A, B}

class D : C {

    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(SomeEnum s) {
        if(s == SomeEnum.A) {
        } else if(s == SomeEnum.B) {
        } 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_

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 28 2011