www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5187] New: Attribute hiding error or warning

http://d.puremagic.com/issues/show_bug.cgi?id=5187

           Summary: Attribute hiding error or warning
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This D code gives no compilation errors with DMD 2.050:


public class Foo {
    public int x = 10;
}
public class Test : Foo {
    public int x = 20;
}
void main() {}





public class Foo {
    public int x = 10;
}
public class Test : Foo {
    public int x = 20; // warning
    public static void Main() {}
}




warning CS0108: `Test.x' hides inherited member `Foo.x'. Use the new keyword if
hiding was intended





public class Foo {
    public int x = 10;
}
public class Test : Foo {
    new public int x = 20; // OK
    public static void Main() {}
}


A similar error (or warning), with a similar "new" keyword solution, may be
added to D, so unwanted hiding of attributes may be avoided.

This is related to using the obligatory "override" keyword:
bug 3836

And this warning that I think is better to become an error ASAP:
bug 4216

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2010