Thread overview
[Issue 6060] New: Refuse wrong final switch
Jan 24, 2012
Denis
Feb 01, 2012
yebblies
May 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6060

           Summary: Refuse wrong final switch
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid, diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2011-05-26 15:56:47 PDT ---
This program compiles and runs with no errors:


void main(string[] args) {
    final switch (args.length) {
        case 0: break;
    }
}


But in such cases I suggest the compiler to statically refuse this code, and give an error.

See also bug 5713 and bug 5714

Note this bug is different from 5713 because in 5713 I don't like an error message (and I'd like the compiler to enforce the presence of the cases for 0,1, and 2), while in this case I'd like an error message.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6060


Denis <verylonglogin.reg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|accepts-invalid             |
                 CC|                            |verylonglogin.reg@gmail.com
           Severity|normal                      |enhancement


--- Comment #1 from Denis <verylonglogin.reg@gmail.com> 2012-01-24 15:22:51 MSK ---
With
https://github.com/D-Programming-Language/dmd/commit/11738ba260ced4d522d2334c5e99059a2517035d
the program throws appropriate exception. And the documentation doesn't claim
the program invalid. So it's an enhancement.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 01, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6060


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com
           Platform|x86                         |All
         OS/Version|Windows                     |All


--- Comment #2 from yebblies <yebblies@gmail.com> 2012-02-01 16:30:04 EST ---
Could you please clarify what this is asking for that issue 5713 doesn't cover?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 05, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6060



--- Comment #3 from bearophile_hugs@eml.cc 2012-02-05 06:50:27 PST ---
(In reply to comment #2)
> Could you please clarify what this is asking for that issue 5713 doesn't cover?

For this program:


void main(string[] args) {
    final switch (args.length) {
        case 0: break;
    }
}


I'd like a compile-time error, like:
"Final switch on ints is not allowed."

-----------------------

For this program:


void main() {
    uint x = 100;
    final switch (x % 3) {
        case 0: break;
        case 1: break;
    }
}


I'd like a compile-time error like:
"Some cases (2) are not covered by the final switch."

So this program is accepted with no errors:

void main() {
    uint x = 100;
    final switch (x % 3) {
        case 0: break;
        case 1: break;
        case 2: break;
    }
}

-----------------------

I am asking for two different error messages, so I have opened two reports.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 05, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6060



--- Comment #4 from bearophile_hugs@eml.cc 2012-02-05 06:51:23 PST ---
(In reply to comment #1)

> And the documentation doesn't claim the program invalid.

It's a broken design.

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