Bug 297 – Shadowing declarations allowed in foreach type lists
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-08-20T07:25:00Z
Last change time
2014-02-15T13:20:59Z
Keywords
accepts-invalid
Assigned to
bugzilla
Creator
matti.niemenmaa+dbugzilla
Comments
Comment #0 by matti.niemenmaa+dbugzilla — 2006-08-20T07:25:26Z
void main() {
int i;
int[] a;
foreach (i; a) {}
foreach (i, n; a) {}
// this fails, the above don't
for (int i;;) {}
}
I don't think this should be allowed, but I'm not entirely certain. Foreaches are, in a way, functions in their own right, passed to the container's opApply, and shadowing in nested functions or function/delegate literals _is_ allowed.
I just still tend to think of foreach loops as only the better way of writing for loops, and since you can't do it with for loops you shouldn't be able to do it with it foreach loops. <g>
Comment #1 by thomas-dloop — 2006-10-02T03:15:37Z
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[email protected] schrieb am 2006-08-20:
> http://d.puremagic.com/issues/show_bug.cgi?id=297
> void main() {
> int i;
> int[] a;
> foreach (i; a) {}
> foreach (i, n; a) {}
>
> // this fails, the above don't
> for (int i;;) {}
> }
>
> I don't think this should be allowed, but I'm not entirely certain. Foreaches
> are, in a way, functions in their own right, passed to the container's opApply,
> and shadowing in nested functions or function/delegate literals _is_ allowed.
>
> I just still tend to think of foreach loops as only the better way of writing
> for loops, and since you can't do it with for loops you shouldn't be able to do
> it with it foreach loops. <g>
Added to DStress as
http://dstress.kuehne.cn/nocompile/f/foreach_37_A.dhttp://dstress.kuehne.cn/nocompile/f/foreach_37_B.dhttp://dstress.kuehne.cn/nocompile/f/foreach_37_C.dhttp://dstress.kuehne.cn/nocompile/f/foreach_37_D.d
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFFINYhLK5blCcjpWoRAn3vAJ9i9VvntyfjLU3yDDpaCeqlU5ZA8gCePKZ5
xiQ4maye+EgY+rZgVOL8k+A=
=nr+N
-----END PGP SIGNATURE-----