Bug 9056 – More precise error messages when function arguments are wrong
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-11-22T14:06:08Z
Last change time
2018-01-02T13:32:54Z
Keywords
diagnostic
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-11-22T14:06:08Z
This is wrong code (it's not meaningful code because it's a full reduction of a much longer program):
struct Foo {}
void bar(in Foo* f4,
in ref Foo f5,
in uint m,
ref const(Foo)* f6,
ref double x,
ref uint n) {}
void main() {
Foo f1;
Foo* f2, f3;
double x = 0;
uint n = 0;
bar(f2, f1, 0, f3, x, n);
}
DMD 2.061alpha gives:
test.d(13): Error: function test.bar (const(Foo*) f4, ref const(Foo) f5, const(uint) m, ref const(Foo)* f6, ref double x, ref uint n) is not callable using argument types (Foo*,Foo,int,Foo*,double,uint)
The function bar() has six arguments. Generally it's better to avoid writing functions with six arguments, especially in languages that don't have "named arguments", but once in a while this happens. In bar() the arguments are tagged in various complex ways. Given such error message it is not immediate to see that this is a good way to fix the code:
struct Foo {}
void bar(in Foo* f4,
in ref Foo f5,
in uint m,
ref const(Foo)* f6,
ref double x,
ref uint n) {}
void main() {
Foo f1;
Foo* f2;
const(Foo)* f3;
double x = 0;
uint n = 0;
bar(f2, f1, 0, f3, x, n);
}
Probably during the compilation the type system of the D compiler has more information. So in my opinion here the compiler should give a more precise error message, that tells what arguments are not acceptable.
In this case the problem is just in the f6 argument of bar(). So I suggest an error message similar to (or better):
test.d(13): Error: function test.bar(const(Foo*) f4, ref const(Foo) f5, const(uint) m, ref const(Foo)* f6, ref double x, ref uint n) is not callable using argument types (Foo*,Foo,int,Foo*,double,uint). The incompatible arguments are: f6.
(Even better is to explain why they are not compatible, but this probably is too much complex to do, so it's better leave this to a future enhancement request.)
Comment #1 by nick — 2017-12-30T17:36:57Z
I've mostly addressed this with a pull for Issue 15613, but I'll leave open because there's also the issue of passing the wrong number of arguments.
Comment #2 by nick — 2018-01-02T13:32:54Z
Ignore that, I was thinking of Issue 16165.
*** This issue has been marked as a duplicate of issue 15613 ***