Thread overview
[Issue 5738] New: error message for template mismatch could be better
Mar 15, 2011
Trass3r
Mar 15, 2011
Trass3r
Apr 07, 2013
Kenji Hara
March 15, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5738

           Summary: error message for template mismatch could be better
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: mrmocool@gmx.de


--- Comment #0 from Trass3r <mrmocool@gmx.de> 2011-03-15 03:20:12 PDT ---
void bla(T...)(T args)
{
    foreach(idx, arg; args)
    blub(idx, arg);
}

void blub(T)(short idx, T arg) // on x64, replace short with int to get a more
real world case
{
}

void main()
{
    bla(5, 2);
}

templ.d(4): Error: template templ.blub(T) does not match any function template
declaration
templ.d(4): Error: template templ.blub(T) cannot deduce template function from
argument types !()(uint,int)
templ.d(4): Error: template templ.blub(T) does not match any function template
declaration
templ.d(4): Error: template templ.blub(T) cannot deduce template function from
argument types !()(uint,int)
templ.d(13): Error: template instance templ.bla!(int,int) error instantiating


It wasn't obvious for me that it couldn't implicitly convert the idx argument.

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


Trass3r <mrmocool@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|minor                       |normal


--- Comment #1 from Trass3r <mrmocool@gmx.de> 2011-03-15 05:26:43 PDT ---
another more cryptic example is the following:

void bla() {}

class Blub
{
    U getInfo(U, alias infoFunction = bla)(uint infoname)
    {
        return 0;
    }

    uint referenceCount() const
    {
        return getInfo!uint(55u);
    }
}

refconst.d(12): Error: template refconst.Blub.getInfo(U,alias infoFunction =
bla) does not match any function template declaration
refconst.d(12): Error: template refconst.Blub.getInfo(U,alias infoFunction =
bla) cannot deduce template function from argument types !(uint)(uint)

The problem is that getInfo needs to be const as well, but there's no hint whatsoever. It's hard to detect that in a big codebase.


Removing alias infoFunction from getInfo results in a slightly less cryptic (but still non-intuitiv message, but that's another issue: http://d.puremagic.com/issues/show_bug.cgi?id=4497):

refconst.d(10): Error: function refconst.Blub.getInfo!(uint).getInfo (uint
infoname) is not callable using argument types (uint) const

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 07, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5738


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WORKSFORME


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2013-04-07 04:41:22 PDT ---
(In reply to comment #0)
[snip]

This code works with 2.063a(git head). IFTI bug might be already fixed.

(In reply to comment #1)
Compiler now reports following errors for the invalid code.

test.d(12): Error: mutable method test.Blub.getInfo!(uint).getInfo is not
callable using a const object

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