www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15396] New: static immutable not recognized as constant

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

          Issue ID: 15396
           Summary: static immutable not recognized as constant within
                    switch statement
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: mathias.lang sociomantic.com

Test case:

`````
static immutable Foo = "Foobar";

void main (string[] args)
{
    foreach (arg; args)
    {
        switch (arg)
        {
        case Foo:
            assert(0);
        default:
            continue;
        }
    }
}
`````

This should be accepted by the compiler but it currently produces:
test.d(9): Error: case must be a string or an integral constant, not Foo

Tested with 2.066 and 2.069.

--
Dec 02 2015