[Issue 18912] [REG 2.080 git] "switch skips declaration" of foreach variable

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun May 27 20:59:33 UTC 2018


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

--- Comment #2 from JR <zorael at gmail.com> ---
I see. The code was naturally heavily reduced.

I have up until now been using the foreach without any issues, though mostly
indexing the .tupleof directly to access the underlying symbol rather than
using the member variable. I only use member once with std.traits.isType.

https://github.com/zorael/kameloso/blob/f4617a5e5c796fcc9797e1f556b0861f44930f40/source/kameloso/config.d#L519

Slightly less reduced:

---

thingloop:
foreach (immutable i, thing; things)
{
    switch (hits["entry"])
    {
        foreach (immutable n, ref member; things[i].tupleof)
        {
            static if (!isType!member &&
                !hasUDA!(Things[i].tupleof[n], Unconfigurable))
            {
                enum memberstring = __traits(identifier,
                    Things[i].tupleof[n]);

                case memberstring:
                    things[i].setMemberByName(hits["entry"],
                        hits["value"]);
                    continue thingloop;
            }
        }

    default:
        // Unknown setting in known section
        invalidEntries[section] ~= hits["entry"].length ? hits["entry"] : line;
        break;
    }
}

---

Thanks, I will try your other approaches.

--


More information about the Digitalmars-d-bugs mailing list