www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22964] New: array cast message is awkwardly worded

https://issues.dlang.org/show_bug.cgi?id=22964

          Issue ID: 22964
           Summary: array cast message is awkwardly worded
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: schveiguy gmail.com

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.

--
Mar 31 2022