On Monday, 8 June 2015 at 22:12:06 UTC, Idan Arye wrote:
On Monday, 8 June 2015 at 21:32:52 UTC, Timon Gehr wrote:
I think the body should have access to a scope that is hidden
from the outside which contains the loop variable, but
declarations should be inserted into the enclosing scope like
for static if.
This would require some syntax to mark the declarations we want
to expose. Maybe `out`?
This is far better than the mixin template approach, since
it'll alert us early about conflicts:
static foreach (ident; ["a", "b", "a"])
{
int mixin(ident ~ "1");
out int mixin(ident ~ "2");
}
`a1` is created twice, but that's OK since it isn't marked with
`out`. `a2` is declared twice and raises a compilation error
because it's marked with `out`. This will ensure these kind of
errors are detected early and the compilation error points to
the exact place of declaration.
I think it would make more sense to behave similar to how static
if currently does.