Bug 319 – local variable can hide member variable

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2006-09-02T16:34:00Z
Last change time
2014-02-15T13:19:15Z
Assigned to
bugzilla
Creator
benoit

Comments

Comment #0 by benoit — 2006-09-02T16:34:45Z
class C{ int mVal; public this(){ int mVal = 2; } public void func(){ int mVal = 2; } } This compiles. But I think using a local variable, hiding a member variable should be illegal.
Comment #1 by bugzilla — 2006-09-02T16:38:50Z
This is an enhancement request.
Comment #2 by ibisbasenji — 2006-09-02T22:05:17Z
[email protected] wrote: > http://d.puremagic.com/issues/show_bug.cgi?id=319 > > Summary: local variable can hide member variable > Product: D > Version: 0.165 > Platform: PC > OS/Version: Linux > Status: NEW > Severity: normal > Priority: P2 > Component: DMD > AssignedTo: [email protected] > ReportedBy: [email protected] > > > class C{ > int mVal; > public this(){ > int mVal = 2; > } > public void func(){ > int mVal = 2; > } > } > > This compiles. But I think using a local variable, hiding a member variable > should be illegal. > I'm sorry but.... why? One can easily disambiguate using the already provided 'this' referance, and there can be perfectly valid reasons to allow this (such as settors and obvious-use constructor parameters). # class C { # int x ; # # public void func () { # int x ; # # x = 2; // modify local variable # this.x = 2; // modify member variable # } # } A warning: maybe. An error: for the love of D, no! -- Chris Nicholson-Sauls
Comment #3 by benoit — 2006-09-03T04:41:38Z
Sorry, I thought it is comparable with the feature from dmd 0.161: "Shadowing local variable declarations is now deprecated." So I set the status to INVALID.