On Saturday, 14 August 2021 at 09:40:54 UTC, kdevel wrote:
Today I stumbled across three issues with partial
initialization of "static" arrays:
~~~i1.d
void main ()
{
char [7] b = [ 1: 'x' ]; // okay
char [7] a = [ 0: 'x' ]; // i1.d(4): Error: mismatched array
lengths, 7 and 1
}
~~~
~~~i2.d
import std.stdio;
void main ()
{
char [7] c7 = [ 1: 'x' ];
writeln (cast (ubyte [7]) c7); // [255, 120, 255, 255, 255,
255, 255] okay
char [7] d7 = "x";
writeln (cast (ubyte [7]) d7); // [120, 0, 0, 0, 0, 0, 0]
would have expected
// [120, 255, 255, 255, 255,
255, 255]
}
~~~
~~~i3.d
// i3.d
void main ()
{
string s = "x";
static assert (is (typeof (s) == typeof ("x")));
assert (s == "x");
char [7] c7 = s; // throws RangeError
}
$ dmd -g i3
$ ./i3
core.exception.RangeError@i3.d(7): Range violation
----------------
??:? _d_arrayboundsp [...]
i3.d:7 _Dmain [...]
~~~
Shall I file them to bugzilla?
Static arrays really don't get any love :(
I also recently filed a bug:
https://issues.dlang.org/show_bug.cgi?id=22198
I think you should also file these ones.
If they're wrong, it'll just get ```RESOLVED INVALID```. Even
better, someone here can tell why the above mentioned behaviours
aren't bugs and you can just do it yourself.