www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 319] New: local variable can hide member variable

reply d-bugmail puremagic.com writes:
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 digitalmars.com
        ReportedBy: benoit 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.


-- 
Sep 02 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=319


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Priority|P2                          |P3





This is an enhancement request.


-- 
Sep 02 2006
prev sibling next sibling parent reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
d-bugmail 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 digitalmars.com
         ReportedBy: benoit 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). A warning: maybe. An error: for the love of D, no! -- Chris Nicholson-Sauls
Sep 02 2006
parent Bruno Medeiros <brunodomedeiros+spam com.gmail> writes:
Chris Nicholson-Sauls wrote:
 d-bugmail 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 digitalmars.com
         ReportedBy: benoit 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). 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
Sep 03 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=319


benoit tionex.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID





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.


-- 
Sep 03 2006