D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22964 - array cast message is awkwardly worded
Summary: array cast message is awkwardly worded
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: diagnostic, pull
Depends on:
Blocks:
 
Reported: 2022-03-31 14:38 UTC by Steven Schveighoffer
Modified: 2022-03-31 23:10 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Steven Schveighoffer 2022-03-31 14:38:15 UTC
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.
Comment 1 Dlang Bot 2022-03-31 14:39:04 UTC
@schveiguy updated dlang/druntime pull request #3792 "Fix confusing message on array cast failure." fixing this issue:

- Fix issue 22964 -- array cast failure message awkwardly worded

https://github.com/dlang/druntime/pull/3792
Comment 2 Dlang Bot 2022-03-31 23:10:15 UTC
dlang/druntime pull request #3792 "Fix confusing message on array cast failure." was merged into master:

- a91547cbb359e3a9b46e52513b457fc05f67298d by Steven Schveighoffer:
  Fix issue 22964 -- array cast failure message awkwardly worded

https://github.com/dlang/druntime/pull/3792