www.digitalmars.com         C & C++   DMDScript  

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

http://d.puremagic.com/issues/show_bug.cgi?id=5669

           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
----
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_

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