[Issue 24073] New: Compiler should explain why implicit conversion to mutable fails
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Aug 5 20:18:31 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24073
Issue ID: 24073
Summary: Compiler should explain why implicit conversion to
mutable fails
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: diagnostic
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: elpenguino+D at gmail.com
There are cases where const values can implicitly convert to mutable, such as
structs without mutable indirections or basic types. However, when this fails,
the compiler does not tell the user why that is. For example...
```
void main() {
const Foo a;
Foo b = a; // okay, no problems here
const Bar c;
//Bar d = c; // Error: cannot implicitly convert expression `c` of type
`const(Bar)` to `Bar`
}
struct Foo {
int value;
}
struct Bar {
void* ptr;
}
```
It would be very helpful if the compiler could offer hints as to why the
implicit conversion failed, similar to attribute inferrence failures. This can
be difficult to track down manually as structs grow in complexity.
--
More information about the Digitalmars-d-bugs
mailing list