[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:12:52 UTC 2021


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

--- Comment #16 from RazvanN <razvan.nitu1305 at gmail.com> ---
(In reply to Walter Bright from comment #15)
> > 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.

But having different error messages depending on the order of declarations is
definitely wrong.

--


More information about the Digitalmars-d-bugs mailing list