D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7259 - Explicit annotation for method hiding
Summary: Explicit annotation for method hiding
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-09 12:50 UTC by bearophile_hugs
Modified: 2021-01-24 06:44 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-01-09 12:50:54 UTC
I'd like to see D care more about this, method hiding:


class Foo {
    string name = "c1";
    static void foo() {}
}
class Bar : Foo {
    string name = "c2";
    static void foo() {} // silent method hiding
}
void main() {}


In such situations I'd like D to require the use of a "new" keyword as C# does (as with 'override', it first becomes a warning):


class Foo {
    string name = "c1";
    static void foo() {}
}
class Bar : Foo {
    string name = "c2";
    static new void foo() {} // method hiding is now visible
}
void main() {}


The point here is to make the purpose and meaning of the code more explicit.

---------------------

See also an answer by Jesse Phillips:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=154448

>> Override usage is going to be (hopefully soon) compulsory in D
>> (currently you need -w to see an error). So that code without
>> both static and override is going to be refused :-)
>
> I guess the question I was getting at, currently there is no way
> to "hide" a non-static member function like you would do in C#
> with 'new.' Is that intended once 'override' is required? and if
> not why have 'new' usable for static methods?
Comment 1 Alex Rønne Petersen 2012-01-09 12:52:24 UTC
I completely agree. If we have mandatory override, we should have this as well.
Comment 3 mhh 2021-01-24 06:44:10 UTC
Language change