## Case 1: ``` void main() { char[32] id = 0; const(char)* str = "hello"; id = str[0 .. 6]; } ``` id is large enough for the string "hello", it should compile instead i get: `` Error: mismatched array lengths 32 and 6 for assignment `id[] = str[0..6] `` ## Case 2: ``` void main() { char[4] id; id = "hello asdad"; } ``` is not not large enough, both string and array length are known at compile time, this shouldn't compile error should be: `` Error: mismatched array lengths 4 and 1 for assignment `id[] = "hello asdad" ``
In case 1 it's unclear what you want, it can be id[0..6]=str[0..6] or id[0..6]=str[0..6],id[6..12]=str[0..6],... - pattern copy.
I expect the same as: ``` void main() { char[32] id = "hello"; } ``` left: static array right: slice result: slice -> copy -> [0 .. slice.length]
char[32] id = 0; const(char)* str = "hello"; id = str[0 .. 6]; The error is correct by the spec: > A static array can be assigned from a dynamic array - the data is copied. The lengths must match https://dlang.org/spec/arrays.html#assignment char[4] id; id = "hello asdad"; This causes a runtime error. You're right it could be caught at compile-time. Assigning an array literal with excess elements is a compile error. char[32] id = "hello"; An array *initializer* is allowed to have fewer elements. If there are excess elements, for an array literal it's a compile error, for a string literal, it's a runtime error as above.
> An array *initializer* is allowed to have fewer elements. Actually that only seems to apply when the initializer is a string literal. char[4] s = [1]; // error char[4] s = "a"; // OK
Spec for above: > A string literal converts to a static array rvalue of the same or longer length https://dlang.org/spec/expression.html#string_literals