Bug 24073 – Compiler should explain why implicit conversion to mutable fails

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-08-05T20:18:31Z
Last change time
2024-12-13T19:30:22Z
Keywords
diagnostic
Assigned to
No Owner
Creator
elpenguino+D
Moved to GitHub: dmd#20318 →

Comments

Comment #0 by elpenguino+D — 2023-08-05T20:18:31Z
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.
Comment #1 by robert.schadek — 2024-12-13T19:30:22Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20318 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB