www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3345] New: Static and nonstatic methods with the same name should be allowed

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3345

           Summary: Static and nonstatic methods with the same name should
                    be allowed
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrei metalanguage.com



10:37:06 PDT ---
Consider:

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

void main() {
    writeln(Widget.fun());       // should print 2
    writeln((new Widget).fun()); // should print 1
}

This should work. Otherwise there is no way to explain how .classinfo works in
terms of D facilities.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 26 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3345


David Simcha <dsimcha yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha yahoo.com



What should be the semantics if there's **only** a static method and no
nonstatic method, i.e.:

class Widget {
    static int fun() { return 2; }
}

void main() {
    // Does this print 2 or not compile?
    writeln((new Widget).fun()); 
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 30 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3345


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy yahoo.com



07:49:41 PDT ---
See proposed enhancement: issue 6579

I think David's example should not compile.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 30 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3345




I would argue that it should be allowed because there's no ambiguity, for two
reasons:

1.  That's the way it already works and changing it would break code and
probably TDPL.

2.  If we're going to make things more verbose, more annoying for generic code
and different from what people from a C++ or Java background expect, we'd
better have a compelling reason.  Your example in Bug 6579 doesn't cut it.  The
root of the problem is that reset() is a poorly chosen name, not that allowing
static methods to be called via an instance is a bad feature.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 30 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3345




08:47:55 PDT ---
I don't want to drag discussions for bug 6579 here, so I responded to your
argument in that bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 30 2011