[Issue 9056] New: More precise error messages when function arguments are wrong
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 22 14:07:43 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9056
Summary: More precise error messages when function arguments
are wrong
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Keywords: diagnostic
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2012-11-22 14:06:08 PST ---
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.)
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list