www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5738] New: error message for template mismatch could be better

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



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


Trass3r <mrmocool gmx.de> changed:

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



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: -------
Mar 15 2011
prev sibling parent d-bugmail puremagic.com writes:
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




[snip]

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


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: -------
Apr 07 2013