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
This should probably be in some DIP, or you could ask about it in the forums. It's worth discussing IMO.
(In reply to Andrej Mitrovic from comment #1) > This should probably be in some DIP, or you could ask about it in the > forums. It's worth discussing IMO. In the D design there are thousands of corner cases that weren't kept into account during the D design, because of reasons. Here I am asking for a warning/error, and for a new usage of "new" (or another semantically equivalent syntax), this is both a breaking change, the introduction of a warning (and a syntax change): things currently seriously frowned upon. Even improvements that lot of people seem to like, like the removal of implicit concatenation of adjacent string literals, or a dangerous and bad corner case: https://github.com/D-Programming-Language/dmd/pull/2887 were refused with insufficient reasons), so are such wars still worth fighting for?
This is documented behavior [1]. There is no need to issue a warning for this. [1] https://dlang.org/spec/class.html#fields