Thread overview
[Issue 4217] New: Function overloads are not distinguished when instantiating templates
May 21, 2010
Shin Fujishiro
May 21, 2010
Shin Fujishiro
May 21, 2010
Shin Fujishiro
Sep 21, 2010
Shin Fujishiro
Oct 12, 2010
Kenji Hara
Dec 06, 2010
Walter Bright
May 21, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4217

           Summary: Function overloads are not distinguished when
                    instantiating templates
           Product: D
           Version: 2.041
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: patch, wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: rsinfu@gmail.com


--- Comment #0 from Shin Fujishiro <rsinfu@gmail.com> 2010-05-21 04:32:09 PDT ---
Created an attachment (id=639)
Patch for DMD svn r496

--------------------
interface I
{
    int test(int);
    real test(real);
}
pragma(msg, typeof(__traits(getOverloads, I, "test")));

template Test(alias func) { pragma(msg, "Test: ", typeof(func)); }
alias Test!(__traits(getOverloads, I, "test")[0]) Test0;
alias Test!(__traits(getOverloads, I, "test")[1]) Test1;

static assert(!__traits(isSame, Test0, Test1));
--------------------
(int(int), real(real))
Test: int(int)
test.d(12): Error: static assert  (!true) is false
--------------------

There is no "Test: real(real)" in the output.  And the two aliases are reported
as the same; the first instance Test0 is reused for the second instantiation
(Test1).

The attached patch fixes the problem by adding a check for overloaded functions to the match() function in template.c.

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


Shin Fujishiro <rsinfu@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #639 is|0                           |1
           obsolete|                            |


--- Comment #1 from Shin Fujishiro <rsinfu@gmail.com> 2010-05-21 15:42:50 PDT ---
Created an attachment (id=640)
Patch for DMD svn r496

I've forgotten to add the essential check: f1 != f2.

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


Shin Fujishiro <rsinfu@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #640 is|0                           |1
           obsolete|                            |


--- Comment #2 from Shin Fujishiro <rsinfu@gmail.com> 2010-05-21 15:54:17 PDT ---
Created an attachment (id=641)
Patch for DMD svn r496

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


Shin Fujishiro <rsinfu@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #641 is|0                           |1
           obsolete|                            |


--- Comment #3 from Shin Fujishiro <rsinfu@gmail.com> 2010-09-21 11:16:09 PDT ---
Created an attachment (id=762)
Patch against dmd r680, implements FuncDeclaration::equals()

Updated patch and a cleaned up test case.
-------------------- test.d
template Return(alias fun)
{
    static if (is(typeof(fun) R == return)) alias R Return;
}

interface I
{
    int  square(int  n);
    real square(real n);
}
alias Return!( __traits(getOverloads, I, "square")[0] ) R0;
alias Return!( __traits(getOverloads, I, "square")[1] ) R1;

static assert(! is(R0 == R1)); // (14)
--------------------
% dmd -o- -c test.d
test.d(14): Error: static assert  (!true) is false
--------------------

The problem is that template alias (symbol) parameters are matched in terms of
the identifier via Dsymbol::equals().  The new patch implements
FuncDeclaration::equals() that checks for function type.

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


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |k.hara.pg@gmail.com


--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2010-10-12 10:12:03 PDT ---
Tested similar code:

--------
template Seq(T...){ alias T Seq; }
class A{
    int f() const{ return 0; }
    int f() immutable{ return 0; }
}
alias Seq!(__traits(getOverloads, A, "f")) Overloads;
template Typeof(alias a)
{
    pragma(msg, typeof(a));
    alias typeof(a) Typeof;
}

static assert(is(Typeof!(Overloads[0]) == typeof(Overloads[0])));
static assert(is(Typeof!(Overloads[1]) == typeof(Overloads[1])));   //should be
OK
--------

It is important for writing meta.algorithm against overload set.

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


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2010-12-05 23:52:59 PST ---
http://www.dsource.org/projects/dmd/changeset/785

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