Thread overview
[Issue 1623] New: Overloading on different parameters numbers gratuitously restrictive.
Oct 29, 2007
d-bugmail
Nov 08, 2007
d-bugmail
Mar 14, 2010
Tomasz Sowiński
Mar 14, 2010
Tomasz Sowiński
Feb 08, 2012
Don
October 29, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1623

           Summary: Overloading on different parameters numbers gratuitously
                    restrictive.
           Product: D
           Version: 2.007
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: andrei@metalanguage.com


Consider:

struct uniformInt(IntType)
{
    static uniformInt opCall()(IntType min, IntType max);
    ResultType opCall(UniformRandomNumberGenerator)
        (ref UniformRandomNumberGenerator urng);
}

The compiler does not allow the overloading, although obviously the functions cannot be confused for one another. This is wrong at multiple levels. Since struct constructors are not allowed, static opCall is about the only decent way to create objects. So even if the parameter counts were the same, overloading should be allowed between static member functions and nonstatic member functions.


-- 

November 08, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1623


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com




------- Comment #1 from smjg@iname.com  2007-11-08 15:49 -------
This doesn't seem to have anything to do with overloading.  As I try it (DMD 1.023 and 2.007 alike, Windows) the code you've posted compiles without error. However, if I trying adding this code:

void main() {
    uniformInt(2, 3);
}

then I get

bz1623.d(2): struct bz1623.uniformInt(IntType) is not a function template
bz1623.d(9): struct bz1623.uniformInt(IntType) cannot deduce template function
f
rom argument types (int,int)

Nothing to do with overloading, but that it's a struct template, not a function template.  If I cut down the example
----------
struct uniformInt(IntType) {
    static uniformInt opCall()(IntType min);
}

void main() {
    uniformInt(42);
}
----------
then I get basically the same errors.

What errors do you get when you try it under Linux?


-- 

March 14, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1623


Tomasz Sowiński <tomeksowi@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tomeksowi@gmail.com


--- Comment #2 from Tomasz Sowiński <tomeksowi@gmail.com> 2010-03-14 10:20:30 PDT ---
I confirm this bug is still present in DMD 2.041. I expect it to be a major hindrance with the new operator overloading regime in which idioms like below are bound to get popular:

struct Matrix {
    Matrix opOpAssign(string op)(real a);
    Matrix opOpAssign(string op)(Matrix m);
}

void main() {
    Matrix a;
    a += 3;
}

Error: template instance opOpAssign!("+=") matches more than one template
declaration, opOpAssign(string op) and opOpAssign(string op)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 14, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1623


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #3 from bearophile_hugs@eml.cc 2010-03-14 12:00:37 PDT ---
Is this useful?

struct Matrix {
    Matrix opOpAssign(string op, T:real)(T a);
    Matrix opOpAssign(string op, T:Matrix)(T m);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 14, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1623



--- Comment #4 from Tomasz Sowiński <tomeksowi@gmail.com> 2010-03-14 13:58:37 PDT ---
(In reply to comment #3)
> Is this useful?
> 
> struct Matrix {
>     Matrix opOpAssign(string op, T:real)(T a);
>     Matrix opOpAssign(string op, T:Matrix)(T m);
> }

It is, thanks. Still, it'd be a lot cleaner to do without dummy template params... Is there some bigger problem that prevents the compiler to look at both template and runtime params when resolving templated function overloads? I'm guessing that it currently matches only against template signatures and bails out upon ambiguity.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 08, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=1623


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug@yahoo.com.au
         Resolution|                            |FIXED


--- Comment #5 from Don <clugdbug@yahoo.com.au> 2012-02-08 06:54:34 PST ---
The test case in comment 2 was fixed in DMD2.049 when bug 4430 was fixed. That seems to be the only valid test case in this bug report.

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