[Issue 5187] New: Attribute hiding error or warning

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 8 04:04:29 PST 2010


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 at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-11-08 04:03:26 PST ---
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() {}



This is equivalent C# code:

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


The C# compiler shows this warning:

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


The following C# code gives no warnings:


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: -------


More information about the Digitalmars-d-bugs mailing list