Static foreach bug?
Petar
Petar
Sun Sep 2 13:26:55 UTC 2018
On Sunday, 2 September 2018 at 13:21:05 UTC, bauss wrote:
> Is there a reason why you cannot create a separate scope within
> a static foreach?
>
> The below will not compile:
>
> ```
> enum a = ["a" : "a", "b" : "b", "c" : "c"];
>
> static foreach (k,v; a)
> {
> {
> enum b = k;
> enum c = v;
> }
> }
> ```
>
> It works if it's in a function of course.
>
> This creates a big limitation when you're trying to ex. loop
> through members of inherited classes, interfaces etc. and then
> want to store the information in variables, because you cannot
> do it. Which means to work around it you have to do it all in
> an ugly one-liner.
>
> Is it intended behavior? If so, why? If not is there a
> workaround until it can be fixed?
It's intended, but with the possibility to add special syntax for
local declarations in the future left open, as per:
https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1010.md#local-declarations
More information about the Digitalmars-d
mailing list