error messages that could be better

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Jun 16 06:22:09 PDT 2013


On 6/16/13, Adam D. Ruppe <destructionator at gmail.com> wrote:
> Yesterday, I was working on a socket code and wrote this:
>
> this(string host, uint port) {
>      socket.connect(new InternetAddress(host, port));
> }
>
> and got this:
>
> server.d(109): Error: constructor std.socket.InternetAddress.this
> () is not callable using argument types (string, uint)
> server.d(109): Error: no constructor for InternetAddress

This is entirely Walter's fault. He removed extra messages from the
error message (despite my objections), leading to confusing errors
like this one.

Otherwise you would have gotten:

test.d(10): Error: constructor std.socket.InternetAddress.this () is
not callable using argument types (string,uint)
test.d(10): Error: expected 1 arguments, not 2 for non-variadic
function type InternetAddress(ushort port)

And this would make it at least informative enough that you can see
the wrong constructor is being called.

Here's another error that went bad:

-----
import core.sys.windows.windows;

pragma(lib, "Advapi32.lib");

void main()
{
    HKEY hKey;
    DWORD dwIndex;
    LPSTR lpValueName;
    LPDWORD lpcbValueName;
    LPDWORD lpReserved;
    LPDWORD lpType;
    LPBYTE lpData;
    LPDWORD lpcbData;
    wchar* valueName = "foo\0"w.dup.ptr;

    RegEnumValueA(hKey, dwIndex, valueName, lpcbValueName, lpReserved,
lpType, lpData, lpcbData);
}
-----

2.063:

test.d(19): Error: function core.sys.windows.windows.RegEnumValueA
(const(void*) hKey, uint dwIndex, char* lpValueName, uint*
lpcbValueName, uint* lpReserved, uint* lpType, ubyte* lpData, uint*
lpcbData) is not callable using argument types
(void*,uint,wchar*,uint*,uint*,uint*,ubyte*,uint*)

Can you spot what's wrong? Try using an earlier compiler:

2.062:

test.d(19): Error: function core.sys.windows.windows.RegEnumValueA
(const(void*) hKey, uint dwIndex, char* lpValueName, uint*
lpcbValueName, uint* lpReserved, uint* lpType, ubyte* lpData, uint*
lpcbData) is not callable using argument types
(void*,uint,wchar*,uint*,uint*,uint*,ubyte*,uint*)
test.d(19): Error: cannot implicitly convert expression (valueName) of
type wchar* to char*

How Walter can argue that the second error isn't useful is beyond
comprehension. He clearly doesn't use D as much as we do to understand
the need for this message.


More information about the Digitalmars-d mailing list