Bug 4889 – Declarator in "if" statement allows name shadowing
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2010-09-18T13:24:55Z
Last change time
2018-10-19T05:48:06Z
Assigned to
No Owner
Creator
Tomash Brechko
Comments
Comment #0 by tomash.brechko — 2010-09-18T13:24:55Z
The following compiles without error with dmd 2.049:
void
main()
{
int i = 1;
if (int i = 2)
{
assert(i == 2);
}
assert(i == 1);
}
It seems prohibiting such shadowing would be in line with block shadowing rules.
Comment #1 by smjg — 2010-09-18T17:26:28Z
I'm not sure if the classification of this as enhancement is correct. The mention of the restriction is under ScopeStatement
"Even though a new scope is introduced, local symbol declarations cannot shadow (hide) other local symbol declarations in the same function."
but was the intent of this statement that it would apply just as well to a variable declared in an if statement? After all, it seems to me that reality its scope is that of the ScopeStatement, even though it isn't lexically within it.
Comment #2 by yebblies — 2011-06-15T08:45:40Z
Errors in D2 (2.053) but still allowed in D1 (1.068)
Comment #3 by bugzilla — 2012-01-23T23:28:02Z
D1 only bug, not a spec issue.
Comment #4 by pro.mathias.lang — 2018-10-19T05:48:06Z