Bug 20369 – shadowed variable in foreach loop always considered "foreach variable"
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-11-08T10:55:55Z
Last change time
2024-01-01T09:23:10Z
Keywords
bootcamp, pull, trivial
Assigned to
No Owner
Creator
Rainer Schuetze
Comments
Comment #0 by r.sagitario — 2019-11-08T10:55:55Z
void foo()
{
string[string] aa;
string text;
foreach(k, v; aa)
{
string text;
}
}
onlineapp.d(7): Deprecation: variable text is shadowing variable onlineapp.foo.text. Rename the foreach variable.
Note that a regular local variable is called "foreach variable".
Comment #1 by razvan.nitu1305 — 2019-11-19T09:58:23Z
I'm not sure I understand this bug report. Is it because the variable inside the foreach loop is referred to as a foreach variable? You would expect something along the lines of "Rename the variable in the foreach body"?
Comment #2 by r.sagitario — 2019-11-19T22:36:52Z
I consider "k" and "v" to be the "foreach variables", not any local variable elsewhere. I don't expect that the compiler tells me that the variable is declared inside the body of a foreach,while,if or similar.
Comment #3 by dlang-bot — 2023-12-20T13:41:40Z
@eoan-ermine created dlang/dmd pull request #15934 "Fix issue 20369 - shadowed variable in foreach loop always considered "foreach variable"" fixing this issue:
- Fix issue 20369 - shadowed variable in foreach loop always considered "foreach variable"
Remove unintuitive phrase in deprecation message
https://github.com/dlang/dmd/pull/15934
Comment #4 by dlang-bot — 2024-01-01T09:23:10Z
dlang/dmd pull request #15934 "Fix issue 20369 - shadowed variable in foreach loop always considered "foreach variable"" was merged into master:
- 8f9476e762b3de323ea86b72a621b8ee92cd6778 by Danil Sidoruk:
Fix issue 20369 - shadowed variable in foreach loop always considered "foreach variable"
* Remove unintuitive phrase in deprecation message
* Fix deprecation message in test
https://github.com/dlang/dmd/pull/15934