Bug 8101 – Display candidate function overloads when function call fails
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-15T11:11:00Z
Last change time
2014-05-02T23:27:04Z
Keywords
diagnostic
Assigned to
andrej.mitrovich
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-05-15T11:11:44Z
int foo(int);
int foo(int, int);
void main() {
foo();
}
DMD 2.060alpha gives:
test.d(4): Error: function test.foo (int) is not callable using argument types ()
test.d(4): Error: expected 2 function arguments, not 0
But a better error message tells that foo() has two overloads, and both are (in this case) not fitting for a zero arguments call. A possible single error message:
test.d(4): no function overloads test.foo matching argument types (). Only test.foo(int) and test.foo(int, int) are defined.
Comment #1 by andrej.mitrovich — 2014-04-28T11:40:56Z
Comment #3 by bearophile_hugs — 2014-05-02T02:53:16Z
The example code:
int foo(int);
int foo(int, int);
void main() {
foo();
}
Now gives:
temp.d(4,8): Error: function temp.foo (int) is not callable using argument types (), candidates are:
temp.d(1,5): temp.foo(int)
temp.d(2,5): temp.foo(int, int)
What's the point of writing "function temp.foo (int)"? If there are overloads and none of them is fitting for the given arguments in the call, then I think it's not useful to show one of the overloads there. So I think a better error message is:
temp.d(4,8): Error: overloaded function temp.foo is not callable using argument types (), candidates are:
temp.d(1,5): temp.foo(int)
temp.d(2,5): temp.foo(int, int)
But the current situation is acceptable, and it's much better than before, so this doesn't matter much.
Comment #4 by andrej.mitrovich — 2014-05-02T07:08:03Z
(In reply to bearophile_hugs from comment #3)
> What's the point of writing "function temp.foo (int)"?
Yes, that's a good point. I'll make a fixup.
Comment #5 by andrej.mitrovich — 2014-05-02T07:30:43Z
(In reply to Andrej Mitrovic from comment #4)
> (In reply to bearophile_hugs from comment #3)
> > What's the point of writing "function temp.foo (int)"?
>
> Yes, that's a good point. I'll make a fixup.
https://github.com/D-Programming-Language/dmd/pull/3520
Comment #6 by bearophile_hugs — 2014-05-02T11:04:32Z
(In reply to Andrej Mitrovic from comment #4)
> (In reply to bearophile_hugs from comment #3)
> > What's the point of writing "function temp.foo (int)"?
>
> Yes, that's a good point. I'll make a fixup.
Sorry for finding the problem here instead in the patch examples.
Comment #7 by github-bugzilla — 2014-05-02T21:34:14Z
Comment #8 by bearophile_hugs — 2014-05-02T22:32:07Z
Now this code:
void foo(int) {}
void foo(int, int) {}
void bar(float) {}
void bar(double) {}
void bar(real) {}
void main() {
foo;
bar(1);
}
Gives:
temp.d(7,5): Error: None of the overloads of 'foo' are callable using argument types (), candidates are:
temp.d(1,6): temp.foo(int _param_0)
temp.d(2,6): temp.foo(int _param_0, int _param_1)
temp.d(8,8): Error: temp.bar called with argument types (int) matches both:
temp.d(3,6): temp.bar(float _param_0)
and:
temp.d(5,6): temp.bar(real _param_0)
It uses the word "both" and it doesn't list temp.bar(double _param_0)
Is this worth opening another ER? :-)
Comment #9 by andrej.mitrovich — 2014-05-02T22:39:33Z
(In reply to bearophile_hugs from comment #8)
> Now
No, not now, that's how it already was. 2.065:
-----
void bar(float) {}
void bar(double) {}
void bar(real) {}
void main() {
bar(1);
}
-----
-----
test.d(5): Error: test.bar called with argument types (int) matches both:
test.d(1): test.bar(float _param_0)
and:
test.d(3): test.bar(real _param_0)
-----
File it as a separate bug.
Comment #10 by bearophile_hugs — 2014-05-02T23:27:04Z
(In reply to Andrej Mitrovic from comment #9)
> File it as a separate bug.
OK, Issue 12694