Bug 8017 – Shadowing declaration not detected in opApply

Status
RESOLVED
Resolution
WONTFIX
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-02T16:56:00Z
Last change time
2016-08-27T22:39:43Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2012-05-02T16:56:48Z
int[int] table; void main() { int foo; foreach (a, b; table) { string foo = ""; } } No error! This happens when iterating hashes. Change the table type to an array (e.g. int[]) and you'll see the shadowing declaration error.
Comment #1 by andrej.mitrovich — 2012-10-03T20:48:35Z
Changing title as this seems related to opApply. This passes: struct Foo { int opApply(int delegate(int, int) dg) { return 1; } } void main() { int foo; foreach (a, b; Foo()) { string foo = ""; } } foreach on a hash probably expands to some opApply code and we end up with the same thing as this sample (just a guess though).
Comment #2 by andrej.mitrovich — 2016-08-27T22:39:43Z
Hm well this is sort of by design, for example there are no errors here: ----- int[int] table; void main() { int foo; void test ( ) { string foo = ""; } } ----- A foreach is really an implicitly generated function just like 'test'.