Help improve error message
Salih Dincer
salihdb at hotmail.com
Sun May 7 11:48:30 UTC 2023
On Saturday, 6 May 2023 at 20:02:30 UTC, ryuukk_ wrote:
> ...
> 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?
The interesting thing is that we encountered this error in
previous versions (eg. v2.087). It hasn't been tried in all
versions, but I'm sure this error will appear at some version. I
encountered this once as well.
Now I tried with the following code. Yes, even with the latest
version I got the same error. However, DMD has such an advanced
error and suggestion mechanism that it guides you how to use
opAssign correctly.
```d
struct Something {
void opAssign(int) {
}
}
void main() {
Something test;/* = 1; /*
`test = 1` is the first assignment of `test` therefore it
represents its initialization
`opAssign` methods are not used for initialization, but for
subsequent assignments//*/
test = 1;/*
// Error: no overload matches for `get`
test.get();//*/
writeln(__VERSION__*.001); // 2.087
}
```
SDB at 79
More information about the Digitalmars-d
mailing list