Help improve error message

ryuukk_ ryuukk.dev at gmail.com
Sat May 6 20:02:30 UTC 2023


First of all, a little quiz


What should the error message be for the following code?

```D
struct Something{}

void main()
{
     Something test;
     test.get();
}
```


Well.. it's not what you expect..



```
onlineapp.d(6): Error: none of the overloads of template 
`object.get` are callable using argument types `!()(Something)`
/dlang/dmd/linux/bin64/../../src/druntime/import/object.d(3442):  
       Candidates are: `get(K, V)(inout(V[K]) aa, K key, lazy 
inout(V) defaultValue)`
/dlang/dmd/linux/bin64/../../src/druntime/import/object.d(3449):  
                       `get(K, V)(inout(V[K])* aa, K key, lazy 
inout(V) defaultValue)`
```

There is the actual error message, surprising right?

``Something`` is not an associative array, so why AA's functions 
are in the candidate list?

What ``Something`` has to do with ``object.get``??


The correct and desirable error message should be:

```
Error: no property `get` for `test` of type `Something`
```

Not something confusing and misleading.. that's hard to debug

Do you agree with that?

If you do and want to improve D, then join me and try to fix that 
behavior!


2 possible solutions that i can think of:

- functions in ``object.d`` should be cleaned, everything that 
has to do with ``AA`` should only work with ``AA``, and 
everything that is generic, should be renamed so it doesn't 
produce conflicts

- DMD should be smarter and the logic for resolving the function 
should reject these functions, so it can produce the proper error 
message


I am obviously clueless, so my 1st attempt was to remove the 
functions plain and simple, it works for me, but that's not the 
proper solution right..

I suspect that the problem lies here: 
https://github.com/dlang/dmd/blob/54b6a2f2b0a129fa3c4a994658d9f99e3a6d4ee3/compiler/src/dmd/func.d#L3265-L3485

Join me and let's make D better (join the IRC channel so we can 
chat about it)


More information about the Digitalmars-d mailing list