www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4217] New: Function overloads are not distinguished when instantiating templates

reply d-bugmail puremagic.com writes:
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



---
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
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4217


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------

           obsolete|                            |



---
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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4217


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------

           obsolete|                            |



---
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: -------
May 21 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4217


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------

           obsolete|                            |



---
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: -------
Sep 21 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Oct 12 2010
prev sibling parent d-bugmail puremagic.com writes:
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



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: -------
Dec 05 2010