Bug 2195 – Variable shadowing in foreach is not detected and reported
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-07-05T10:22:14Z
Last change time
2019-09-12T14:29:32Z
Keywords
accepts-invalid, pull
Assigned to
No Owner
Creator
Koroskin Denis
Comments
Comment #0 by 2korden — 2008-07-05T10:22:14Z
Test case that fails as of 1.026 (earlist one I have) as well as latest one (1.031 atm).
void main() {
int[int] arr;
int variable;
foreach (i, j; arr) {
int variable; // shadowing is disallowed but not detected
}
}
Comment #1 by smjg — 2010-08-19T06:28:38Z
*** This issue has been marked as a duplicate of issue 47 ***
Comment #2 by smjg — 2010-08-19T06:37:15Z
I was wrong, the bug has come back (1.063 and 2.048, Windows).
Comment #3 by clugdbug — 2010-08-31T02:43:31Z
(In reply to comment #2)
> I was wrong, the bug has come back (1.063 and 2.048, Windows).
I tested 0.165, 1.000, 1.020, 1.032, 1.041, 1.050, 1.060 and a few others.
This is not a regression. The bug was never gone.
Comment #4 by smjg — 2010-08-31T04:21:58Z
(In reply to comment #3)
> (In reply to comment #2)
> > I was wrong, the bug has come back (1.063 and 2.048, Windows).
>
> I tested 0.165, 1.000, 1.020, 1.032, 1.041, 1.050, 1.060 and a few others.
> This is not a regression. The bug was never gone.
In that case, any clue why bug 47 was logged as fixed in 0.161, both on the bug page and in the changelog?
Comment #5 by clugdbug — 2010-08-31T04:37:13Z
(In reply to comment #4)
> (In reply to comment #3)
> > (In reply to comment #2)
> > > I was wrong, the bug has come back (1.063 and 2.048, Windows).
> >
> > I tested 0.165, 1.000, 1.020, 1.032, 1.041, 1.050, 1.060 and a few others.
> > This is not a regression. The bug was never gone.
>
> In that case, any clue why bug 47 was logged as fixed in 0.161, both on the bug
> page and in the changelog?
Bug 47 was fixed, and still is. This isn't a duplicate. It applies only with foreach().
Comment #6 by yebblies — 2012-01-29T20:56:24Z
Related to issue 2192. This only applies when foreach turns the body into a delegate.
Comment #7 by michal.minich — 2012-08-24T02:46:04Z
DMD 2.060
Similar case, where the variable is declared as foreach type list identifier
module main;
int global;
int main (string[] args)
{
// int global = 10; // Error: shadowing declaration main.main.global
// is deprecate .. ok
foreach (global, item; [1, 2, 3]) // no error reported here for global ..
// but expected
{}
writeln(global); // prints 0
}
Comment #8 by yebblies — 2012-10-28T13:38:42Z
(In reply to comment #7)
> DMD 2.060
>
> Similar case, where the variable is declared as foreach type list identifier
>
> [snip]
This case is not a bug/not this bug, local variables are allowed to shadow globals.
Comment #9 by hsteoh — 2014-07-19T01:29:05Z
Still present in git HEAD, compiler accepts the code without error.
Comment #10 by dlang-bot — 2019-09-12T11:16:24Z
@RazvanN7 created dlang/dmd pull request #10404 "Fix Issue 2195 - Variable shadowing in foreach is not detected and reported" fixing this issue:
- Fix Issue 2195 - Variable shadowing in foreach is not detected and reported
https://github.com/dlang/dmd/pull/10404
Comment #11 by dlang-bot — 2019-09-12T14:29:32Z
dlang/dmd pull request #10404 "Fix Issue 2195 - Variable shadowing in foreach is not detected and reported" was merged into master:
- 08399aa0858aa336bec632a8f4110c381c61ea4e by RazvanN7:
Fix Issue 2195 - Variable shadowing in foreach is not detected and reported
https://github.com/dlang/dmd/pull/10404