dmd/changelog/dmd.error-messages.dd

104 lines
2.9 KiB
Text

Many error messages have changed
Some changes have been made without being associated to a reported issue:
Error messages for `@safe` violations now consistently mention they are related to `@safe` functions (or default functions with `-preview=safer`).
In general, function attributes that failed to infer have a more compact error message:
---
/*
BEFORE:
app.d(8): Error: function `attributediagnostic_nothrow.gc1` is not `nothrow`
app.d(2): which wasn't inferred `nothrow` because of:
app.d(2): `object.Exception` is thrown but not caught
AFTER:
app.d(8): Error: function `attributediagnostic_nothrow.gc1` is not `nothrow`
app.d(2): and `object.Exception` being thrown but not caught makes it fail to infer `nothrow`
*/
---
Match levels are now mentioned on ambiguous overloads: [#20637](https://github.com/dlang/dmd/pull/20637)
---
/*
BEFORE:
Error: `app.bar` called with argument types `(string)` matches both:
AFTER:
Error: `app.bar` called with argument types `(string)` matches multiple overloads after implicit conversions:
*/
---
When there's no index / slice operator overload found for a type, a new supplemental message suggests where to implement it.
---
struct S {}
void main()
{
S s;
const x = s[3 .. "4"];
}
/*
Before:
app.d(6): Error: no `[]` operator overload for type `S`
After:
app.d(6): Error: no `[3.."4"]` operator overload for type `S`
app.d(1): perhaps define `auto opSlice(int lower, string upper) {}` for `app.S`
*/
---
When overloading binary operators, and `opBinary`, `opBinaryRight` or `opOpAssign` is missing / fails to instantiate,
the error message now points out the problem:
---
struct Str {}
struct Number
{
int x;
int opBinary(string op : "+")(int rhs) => this.x + x;
}
void f(Str str, Number number)
{
const s = str ~ "hey";
const n = number + "oops";
}
/*
Before:
app.d(12): Error: incompatible types for `(str) ~ ("hey")`: `Str` and `string`
const s = str ~ "hey";
^
app.d(13): Error: incompatible types for `(number) + ("oops")`: `Number` and `string`
const n = number + "oops";
After:
app.d(12): Error: operator `~` is not defined for type `Str`
const s = str ~ "hey";
^
app.d(2): perhaps overload the operator with `auto opBinary(string op : "~")(string rhs) {}`
struct Str {}
^
app.d(13): Error: function `test_.Number.opBinary!"+".opBinary(int rhs)` is not callable using argument types `(string)`
const n = number + "oops";
^
app.d(13): cannot pass argument `"oops"` of type `string` to parameter `int rhs`
app.d(7): `opBinary` defined here
int opBinary(string op : "+")(int rhs) => this.x + x;
^
*/
---
Furthermore:
- D1 operator overloading functions (`opAdd`, `opDot`) are completely removed and no longer mentioned in error messages specifically.
- Class allocators (`auto new() {}`) are not only a semantic error, but no longer being parsed