www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18912] New: [REG 2.080 git] "switch skips declaration" of

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

          Issue ID: 18912
           Summary: [REG 2.080 git] "switch skips declaration" of foreach
                    variable
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: zorael gmail.com

I have a function with a switch, with an inner foreach to generate cases based
on a template parameters .tupleof. It still works in 2.080.0 and even with
"dmd-nightly" on run.dlang.io, but not with dmd from git as of 180527.

---

struct Foo
{
    string abc, def;
}

void applyConfiguration(Thing)(ref Thing thing)
{
    switch ("asdf")
    {
        foreach (immutable n, ref member; thing.tupleof)
        {
            enum memberstring = __traits(identifier, Thing.tupleof[n]);

            case memberstring:
                // ...
                break;
        }

    default:
        break;
    }
}

void main()
{
    Foo foo;
    applyConfiguration(foo);
}

---

 switch.d(8): Error: `switch` skips declaration of variable
`switch.applyConfiguration!(Foo).applyConfiguration.member` at switch.d(11)
 switch.d(27): Error: template instance `switch.applyConfiguration!(Foo)` error
instantiating
The offending commit is eabc6a62b1d2f5924637f1e61464b9a975341dd4, "fix Issue 18858 - switch 'skips declaration' test only checks last declaration". Is this a regression or was my code always broken? --
May 27 2018