[Issue 5862] case statement allows runtime values

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Aug 27 14:43:06 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=5862

Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #7 from Andrej Mitrovic <andrej.mitrovich at gmail.com> ---
As mentioned in the pull request the proposal to disallow this was rejected.

I would like to remind about this:

-----
import std.stdio;

void main()
{
    int first = 1;
    int second = 1;

    switch (1)
    {
        case first:
        {
            writeln("first");
            break;
        }

        case second:
        {
            writeln("second");
            break;
        }

        default:
    }
}
-----

The lexically first matching case will match. That's ok, but it should probably
be documented if it's not (this style of code should be rare in the wild in any
case).

--


More information about the Digitalmars-d-bugs mailing list