Bug 22964 – array cast message is awkwardly worded
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-03-31T14:38:15Z
Last change time
2022-03-31T23:10:15Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
Steven Schveighoffer
Comments
Comment #0 by schveiguy — 2022-03-31T14:38:15Z
Given the following code:
```d
auto str = "hello";
auto wstr = cast(wstring)str;
```
The array cast cannot complete, because it would require 2.5 wchars. Regardless of the correctness of this attempt, the message is confusing:
```
An array of size 5 does not align on an array of size 4, so `immutable(char)` cannot be cast to `immutable(wchar)`
```
1. I never requested an array of size 4, so I'm not sure why that is in the message.
2. It's not a matter of alignment, but of size.
3. You can cast an immutable char to an immutable wchar, so the message is wrong
4. The bytes are displayed here, not the lengths, which isn't as useful, there is no need to have the user work out the math.
I am writing a PR to fix this message, this is the bug report for that fix.