[Issue 319] New: local variable can hide member variable
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Sun Sep 3 03:06:33 PDT 2006
Chris Nicholson-Sauls wrote:
> d-bugmail at puremagic.com 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: bugzilla at digitalmars.com
>> ReportedBy: benoit at tionex.de
>>
>>
>> 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
I often end up using stuff like that in constructors:
class C {
int x ;
public this (int x) {
this.x = x;
}
}
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d-bugs
mailing list