Comment #0 by bearophile_hugs — 2013-02-22T11:09:10Z
void main() {
int[300] data;
foreach (ubyte i, x; data) {} // Line 3, no error.
ubyte j = data.length; // Line 4, Error.
}
DMD 2.063alpha gives:
temp.d(4): Error: cannot implicitly convert expression (300u) of type uint to ubyte
But line 3 should give a similar error message, because data has 300 items, so the "i" index can't represent all the possible indexes.
See also issue 9570.
Comment #3 by bearophile_hugs — 2013-11-23T04:56:35Z
void main() {
int[300] data;
foreach (ubyte i, x; data) {} // Line 3, no error.
ubyte j = data.length; // Line 4, Error.
}
Now the error messages are correct (but there is an extra newline in the middle):
temp.d(3): Error: index type 'ubyte' cannot cover index range 0..300
temp.d(4): Error: cannot implicitly convert expression (300u) of type uint to ubyte