Comment #0 by pro.mathias.lang — 2021-03-22T07:54:34Z
```
import std.meta;
import std.stdio;
void main ()
{
foreach (idx, T; AliasSeq!(int, char, bool, int, string, int, ubyte))
{
void checkValue (TT) (TT value, size_t id)
{
assert(id == idx);
assert(value == TT.init);
}
checkValue(T.init, idx);
}
writeln("Yep");
}
```
Since the fix for https://issues.dlang.org/show_bug.cgi?id=14831 this runs correctly. However trying to make the `foreach` static will lead to the following errors:
```
foo.d(8): Error: declaration `checkValue(TT)(TT value, size_t id)` is already defined
foo.d(8): `template` `checkValue(TT)(TT value, size_t id)` is defined here
foo.d(8): Error: declaration `checkValue(TT)(TT value, size_t id)` is already defined
foo.d(8): `template` `checkValue(TT)(TT value, size_t id)` is defined here
foo.d(8): Error: declaration `checkValue(TT)(TT value, size_t id)` is already defined
foo.d(8): `template` `checkValue(TT)(TT value, size_t id)` is defined here
foo.d(8): Error: declaration `checkValue(TT)(TT value, size_t id)` is already defined
foo.d(8): `template` `checkValue(TT)(TT value, size_t id)` is defined here
foo.d(8): Error: declaration `checkValue(TT)(TT value, size_t id)` is already defined
foo.d(8): `template` `checkValue(TT)(TT value, size_t id)` is defined here
foo.d(8): Error: declaration `checkValue(TT)(TT value, size_t id)` is already defined
foo.d(8): `template` `checkValue(TT)(TT value, size_t id)` is defined here
```
Obviously this is an unwarranted limitation.
Comment #1 by moonlightsentinel — 2021-03-22T09:58:17Z
Ins't that expected behavior? `static foreach` explicitly does not create a new scope while "normal" foreach does.
Comment #2 by pro.mathias.lang — 2021-03-25T04:22:24Z
You're correct. I guess I have to get used to `static foreach (...) {{ /* CODE GOES HERE */ }}`.