Bug 16548 – Shadowing a variable not detected when nesting foreach with associative arrays
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-09-26T19:59:42Z
Last change time
2019-11-08T10:57:18Z
Keywords
accepts-invalid, diagnostic
Assigned to
No Owner
Creator
skocznymr
Comments
Comment #0 by skocznymr — 2016-09-26T19:59:42Z
Reproduces on git HEAD.
This code:
void main()
{
int[int] x;
foreach (int a; x)
{
foreach (int a; x)
{
}
}
}
should generate a compile error "variable a is shadowing variable a", but it doesn't.
When using non-associative arrays, the error is generated properly.
Comment #1 by dlang-bugzilla — 2017-09-22T20:13:02Z
Second variable doesn't need to be a foreach variable, either:
/////// test.d ///////
void main()
{
int x;
int[int] aa;
foreach (k, v; aa)
{
int x;
}
}
//////////////////////
Comment #2 by r.sagitario — 2019-11-08T10:51:09Z
*** Issue 11923 has been marked as a duplicate of this issue. ***
Comment #3 by r.sagitario — 2019-11-08T10:57:18Z
Works in dmd 2.089, with a slight diagnostic inaccuracy: issue 20369