On Saturday, 14 August 2021 at 14:33:42 UTC, kdevel wrote:
On Saturday, 14 August 2021 at 14:18:57 UTC, Tejas wrote:
On Saturday, 14 August 2021 at 14:04:47 UTC, kdevel wrote:
On Saturday, 14 August 2021 at 13:01:13 UTC, frame wrote:
I would say case [...] 3 is not [a bug]. It's just the
element type conversion and mismatched lengths of the ranges.
~~~
char [7] d7 = "x"; // okay
string s = "x";
char [7] c7 = s; // throws RangeError
~~~
What justifies that the compiler behaves differently on two
terms ('s', '"x"') which are of equal size, type, length and
value?
They are not.
assert(string.sizeof != char.sizeof);
The terms are s and "x":
~~~r.d
void main ()
{
string s = "x";
assert (s.sizeof == "x".sizeof);
}
~~~
It did implicit conversion on the literal but not the variable.
Basically,
```d
char[7] a = cast(char[7])"x"; // works
string s = "x";
char[7] b = cast(char[7])s; //fails
```
That's my best guess.
Hopefully someone more experienced chimes in.