[Issue 3345] Static and nonstatic methods with the same name should be allowed

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 30 10:02:49 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=3345

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com

--- Comment #15 from Walter Bright <bugzilla at digitalmars.com> ---
> Otherwise there is no way to explain how .classinfo works in terms of D facilities.

It is explained by if the member function is static, the 'this' reference is
used for its type.

    writeln(Widget.fun());       // Widget is a type
    writeln((new Widget).fun()); // (new Widget) gives the type

This is so that member functions that don't need the `this` reference can still
work fine if the `this` reference is provided.

This explains the overloading behavior. The compiler and language is working as
designed.

For code like this:

    int fun() { return 1; }
    static int fun() { return 2; }

I cannot understand what purpose there is for writing such code.

--


More information about the Digitalmars-d-bugs mailing list