Skip to content

Commit

Permalink
Merge pull request #1197 from Poita/templateCandidates
Browse files Browse the repository at this point in the history
Failed template match error now lists candidates.
  • Loading branch information
WalterBright committed Nov 10, 2012
2 parents 9adb5a0 + 175594c commit 9b4c8ee
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -2131,8 +2131,28 @@ FuncDeclaration *TemplateDeclaration::deduceFunctionTemplate(Scope *sc, Loc loc,
if (!td_best)
{
if (!(flags & 1))
::error(loc, "%s %s.%s does not match any function template declaration",
{
::error(loc, "%s %s.%s does not match any function template declaration. Candidates are:",
kind(), parent->toPrettyChars(), ident->toChars());

// Display candidate template functions
int numToDisplay = 5; // sensible number to display
for (TemplateDeclaration *td = this; td; td = td->overnext)
{
::errorSupplemental(td->loc, "%s", td->toPrettyChars());
if (!global.params.verbose && --numToDisplay == 0)
{
// Too many overloads to sensibly display.
// Just show count of remaining overloads.
int remaining = 0;
for (; td; td = td->overnext)
++remaining;
if (remaining > 0)
::errorSupplemental(loc, "... (%d more, -v to show) ...", remaining);
break;
}
}
}
goto Lerror;
}
if (td_ambig)
Expand Down Expand Up @@ -2357,6 +2377,18 @@ char *TemplateDeclaration::toChars()
tp->toCBuffer(&buf, &hgs);
}
buf.writeByte(')');

if (onemember && onemember->toAlias())
{
FuncDeclaration *fd = onemember->toAlias()->isFuncDeclaration();
if (fd && fd->type)
{
TypeFunction *tf = (TypeFunction *)fd->type;
char const* args = Parameter::argsTypesToChars(tf->parameters, tf->varargs);
buf.writestring(args);
}
}

#if DMDV2
if (constraint)
{ buf.writestring(" if (");
Expand Down

0 comments on commit 9b4c8ee

Please sign in to comment.