Improve error messages for opUnary (#20801)

This commit is contained in:
Dennis 2025-01-30 12:44:05 +01:00 committed by GitHub
parent 06e0096aca
commit 06d0cfe2ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 192 additions and 173 deletions

View file

@ -30,7 +30,12 @@ Error: `app.bar` called with argument types `(string)` matches multiple overload
*/
---
When there's no index / slice operator overload found for a type, a new supplemental message suggests where to implement it.
Error messages related to operator overloading have been improved.
When the related template functions (`opUnary`, `opBinary`, `opBinaryRight`, `opOpAssign`, `opIndex`, `opSlice`)
are missing, a suggestion to implement them is given.
When they do exist but fail to instantiate, the error from instantiation is shown.
There's no longer a need to manually e.g. rewrite `s + 1` to `s.opBinary!"+"(1)` to diagnose the error.
---
struct S {}
@ -53,9 +58,6 @@ app.d(1): perhaps define `auto opSlice(int lower, string upper) {}` for `
*/
---
When overloading binary operators, and `opBinary`, `opBinaryRight` or `opOpAssign` is missing / fails to instantiate,
the error message now points out the problem:
---
struct Str {}