Skip to content

Commit

Permalink
Fix Issue 8101 - Fixup pull improving diagnostics when there are over…
Browse files Browse the repository at this point in the history
…loads.
  • Loading branch information
AndrejMitrovic committed May 2, 2014
1 parent 58445fb commit cc37567
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
26 changes: 17 additions & 9 deletions src/func.c
Expand Up @@ -3258,27 +3258,35 @@ FuncDeclaration *resolveFuncCall(Loc loc, Scope *sc, Dsymbol *s,
{
assert(fd);

const char *trailMsg = (fd->overnext != NULL) ? ", candidates are:" : "";
bool hasOverloads = fd->overnext != NULL;
TypeFunction *tf = (TypeFunction *)fd->type;
if (tthis && !MODimplicitConv(tthis->mod, tf->mod)) // modifier mismatch
{
OutBuffer thisBuf, funcBuf;
MODMatchToBuffer(&thisBuf, tthis->mod, tf->mod);
MODMatchToBuffer(&funcBuf, tf->mod, tthis->mod);
::error(loc, "%smethod %s is not callable using a %sobject%s",
funcBuf.peekString(), fd->toPrettyChars(), thisBuf.peekString(), trailMsg);
if (hasOverloads)
::error(loc, "None of the overloads of '%s' are callable using a %sobject, candidates are:",
fd->ident->toChars(), thisBuf.peekString());
else
::error(loc, "%smethod %s is not callable using a %sobject",
funcBuf.peekString(), fd->toPrettyChars(), thisBuf.peekString());
}
else
{
//printf("tf = %s, args = %s\n", tf->deco, (*fargs)[0]->type->deco);
fd->error(loc, "%s%s is not callable using argument types %s%s",
Parameter::argsTypesToChars(tf->parameters, tf->varargs),
tf->modToChars(),
fargsBuf.peekString(), trailMsg);
if (hasOverloads)
::error(loc, "None of the overloads of '%s' are callable using argument types %s, candidates are:",
fd->ident->toChars(), fargsBuf.peekString());
else
fd->error(loc, "%s%s is not callable using argument types %s",
Parameter::argsTypesToChars(tf->parameters, tf->varargs),
tf->modToChars(),
fargsBuf.peekString());
}

// Display candidate functions (only when there are multiple overloads)
if (fd->overnext)
// Display candidate functions
if (hasOverloads)
{
FuncCandidateWalker fcw;
fcw.loc = loc;
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/diag10415.d
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag10415.d(36): Error: function diag10415.C.x () const is not callable using argument types (int) const, candidates are:
fail_compilation/diag10415.d(36): Error: None of the overloads of 'x' are callable using argument types (int) const, candidates are:
fail_compilation/diag10415.d(13): diag10415.C.x()
fail_compilation/diag10415.d(18): diag10415.C.x(int _param_0)
fail_compilation/diag10415.d(39): Error: d.x is not an lvalue
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/diag11078.d
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag11078.d(19): Error: function diag11078.S1.value () is not callable using argument types (double), candidates are:
fail_compilation/diag11078.d(19): Error: None of the overloads of 'value' are callable using argument types (double), candidates are:
fail_compilation/diag11078.d(12): diag11078.S1.value()
fail_compilation/diag11078.d(13): diag11078.S1.value(int n)
---
Expand Down
4 changes: 2 additions & 2 deletions test/fail_compilation/diag8101.d
Expand Up @@ -2,10 +2,10 @@
TEST_OUTPUT:
---
fail_compilation/diag8101.d(56): Error: function diag8101.f_0 (int) is not callable using argument types ()
fail_compilation/diag8101.d(57): Error: function diag8101.f_1 (int) is not callable using argument types (), candidates are:
fail_compilation/diag8101.d(57): Error: None of the overloads of 'f_1' are callable using argument types (), candidates are:
fail_compilation/diag8101.d(32): diag8101.f_1(int)
fail_compilation/diag8101.d(33): diag8101.f_1(int, int)
fail_compilation/diag8101.d(58): Error: function diag8101.f_2 (int) is not callable using argument types (), candidates are:
fail_compilation/diag8101.d(58): Error: None of the overloads of 'f_2' are callable using argument types (), candidates are:
fail_compilation/diag8101.d(35): diag8101.f_2(int)
fail_compilation/diag8101.d(36): diag8101.f_2(int, int)
fail_compilation/diag8101.d(37): diag8101.f_2(int, int, int)
Expand Down
34 changes: 34 additions & 0 deletions test/fail_compilation/diag8101b.d
@@ -0,0 +1,34 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag8101b.d(26): Error: None of the overloads of 'foo' are callable using argument types (double), candidates are:
fail_compilation/diag8101b.d(17): diag8101b.S.foo(int _param_0)
fail_compilation/diag8101b.d(18): diag8101b.S.foo(int _param_0, int _param_1)
fail_compilation/diag8101b.d(28): Error: function diag8101b.S.bar (int _param_0) is not callable using argument types (double)
fail_compilation/diag8101b.d(31): Error: None of the overloads of 'foo' are callable using a const object, candidates are:
fail_compilation/diag8101b.d(17): diag8101b.S.foo(int _param_0)
fail_compilation/diag8101b.d(18): diag8101b.S.foo(int _param_0, int _param_1)
fail_compilation/diag8101b.d(33): Error: mutable method diag8101b.S.bar is not callable using a const object
---
*/

struct S
{
void foo(int) { }
void foo(int, int) { }

void bar(int) { }
}

void main()
{
S s;
s.foo(1.0);

s.bar(1.0);

const(S) cs;
cs.foo(1);

cs.bar(1);
}

0 comments on commit cc37567

Please sign in to comment.