Improve error message for "function is not callable using argument"
Paul Backus
snarwin at gmail.com
Mon Apr 3 16:21:38 UTC 2023
On Sunday, 2 April 2023 at 13:43:59 UTC, ryuukk_ wrote:
> ```
> Error: function `proxy.injector.RemoteLibraryFunction(void*
> hProcess, const(wchar)* lpModuleName, const(wchar)* lpProcName,
> void* lpParameters, ulong dwParamSize, void** ppReturn)` is not
> callable using argument
> types `(void*, const(wchar)*, wchar[512], void*, int, void**)`
> ```
>
> While writing this post i just remembered that i attempted a PR
> few years ago: https://github.com/dlang/dmd/pull/13366
>
> This is always painful to read/decipher, can this error be
> improved?
>
> At least colors/arrows to tell me wich argument(s) are wrong
>
> Perhaps on a new line?
>
> Unfortunately, I have no ideas how to improve it, anyone mind
> helping me?
>
> Thanks!
I attempted to reproduce your issue using the following example
code:
```d
void RemoteLibraryFunction(
void* hProcess,
const(wchar)* lpModuleName,
const(wchar)* lpProcName,
void* lpParameters,
ulong dwParamSize,
void** ppReturn
);
void main()
{
void* vp;
const(wchar)* cwcp;
wchar[512] wca;
int n;
void** vpp;
RemoteLibraryFunction(vp, cwcp, wca, vp, n, vpp);
}
```
Attempting to compile this code with DMD v2.102.2 produced the
following output:
```
example.d(18): Error: function
`example.RemoteLibraryFunction(void* hProcess, const(wchar)*
lpModuleName, const(wchar)* lpProcName, void* lpParameters, ulong
dwParamSize, void** ppReturn)` is not callable using argument
types `(void*, const(wchar)*, wchar[512], void*, int, void**)`
example.d(18): cannot pass argument `wca` of type
`wchar[512]` to parameter `const(wchar)* lpProcName`
```
Note the last line, which points out the specific argument that
does not match. According to the changelog, that line was added
in DMD v2.079.0:
https://dlang.org/changelog/2.079.0.html#argument-mismatch
So, unless you are using an extremely old D compiler, you should
be seeing that line in your compiler's output.
More information about the Digitalmars-d
mailing list