[Issue 14728] New: Problems in the switch statement with enumerated data types

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jun 23 13:40:25 PDT 2015


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

          Issue ID: 14728
           Summary: Problems in the switch statement with enumerated data
                    types
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dennis.m.ritchie at mail.ru

Found by Denis M...
https://vk.com/topic-471951_32042913

I think it can not write, but still it is a strange behavior and sometimes even
compile.

`````
import std.stdio;

void main()
{
    int x = 1;
    long y = 2;

    switch(x, y) {
        case x : writeln("1"); break;
        // Error: variable x cannot be read at compile time
        case y : writeln("2"); break;
        default: break;
    }
}
`````
import std.stdio;

// compiles

void main()
{
    int x = 1;
    int y = 2;

    switch(x, y) {
        case x : writeln("1"); break;
        case y : writeln("2"); break;
        default: break;
    }
}

I think that should be banned in the switch to send the enumerated arguments
T...

--


More information about the Digitalmars-d-bugs mailing list