Thread overview
error messages that could be better
Jun 16, 2013
Adam D. Ruppe
Jun 16, 2013
Andrej Mitrovic
Jun 19, 2013
Adam D. Ruppe
Jun 19, 2013
Andrej Mitrovic
Jun 19, 2013
Adam D. Ruppe
June 16, 2013
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


It took me several minutes to realize my real mistake: I wrote "uint" when I meant "ushort". The error message was less than helpful because I was quite certain this was how it worked, but it was complaining about this() rather than this(string, ushort), so maybe I forgot how to construct this thing.



The error messages can catch simple spelling errors with a distance of one edit from the correct name, but here it couldn't catch a type mismatch with a similar distance of one from the real thing.

If it did that, I would have spent 5 seconds on this rather than 5 minutes.
June 16, 2013
On 6/16/13, Adam D. Ruppe <destructionator@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.
June 16, 2013
On 6/16/13 9:04 AM, Adam D. Ruppe 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
>
>
> It took me several minutes to realize my real mistake: I wrote "uint"
> when I meant "ushort". The error message was less than helpful because I
> was quite certain this was how it worked, but it was complaining about
> this() rather than this(string, ushort), so maybe I forgot how to
> construct this thing.
>
>
>
> The error messages can catch simple spelling errors with a distance of
> one edit from the correct name, but here it couldn't catch a type
> mismatch with a similar distance of one from the real thing.
>
> If it did that, I would have spent 5 seconds on this rather than 5 minutes.

At a minimum the full signature should be in the error message.

server.d(109): Error: constructor std.socket.InternetAddress.this(string, ushort) is not callable using argument types (string, uint)


Andrei
June 19, 2013
Here's another bad one:

admin.d(53): Error: not a property ta.innerHTML


I assigned an int to it instead of a string, but the error message doesn't say that, it makes me think I have the entirely wrong name, or ta isn't the type I think it is.


The error messages in general seem to have been moving backward the last few releases.
June 19, 2013
On 6/20/13, Adam D. Ruppe <destructionator@gmail.com> wrote:
> Here's another bad one:
>
> admin.d(53): Error: not a property ta.innerHTML

File it, please. Once it's fixed it'll go into diagnostic tests and should not become bad again in new releases.
June 19, 2013
On Wednesday, 19 June 2013 at 23:03:50 UTC, Andrej Mitrovic wrote:
> File it, please.

http://d.puremagic.com/issues/show_bug.cgi?id=10418

The same principle applies to this and the constructor one I complained about before, and I think it can to overloaded functions in general.