error about too many elements in initializer; added test for initialized arrays: arrays2.tmpl/qc

This commit is contained in:
Wolfgang Bumiller 2013-06-12 14:41:38 +02:00
parent 633d2ba8a4
commit dc91918c1f
4 changed files with 36 additions and 5 deletions

10
ast.c
View file

@ -1212,6 +1212,16 @@ static bool ast_global_array_set(ast_value *self)
size_t count = vec_size(self->initlist); size_t count = vec_size(self->initlist);
size_t i; size_t i;
if (count > self->expression.count) {
compile_error(ast_ctx(self), "too many elements in initializer");
count = self->expression.count;
}
else if (count < self->expression.count) {
/* add this?
compile_warning(ast_ctx(self), "not all elements are initialized");
*/
}
for (i = 0; i != count; ++i) { for (i = 0; i != count; ++i) {
switch (self->expression.next->vtype) { switch (self->expression.next->vtype) {
case TYPE_FLOAT: case TYPE_FLOAT:

View file

@ -1,7 +1,6 @@
I: arrays.qc I: arrays2.qc
D: array accessors and functionality D: initialized arrays
T: -execute T: -execute
C: -std=fteqcc C: -std=fteqcc
M: 1001 1101 1201 1301 1401 1501 M: 10 20 30 40 50 60 70
M: 1001 1101 1201 1301 1401 1501 1601 M: 100 200 300 400 500 600 0
M: 1001 1101 1201 1301 1401 1501

15
tests/arrays2.qc Normal file
View file

@ -0,0 +1,15 @@
float glob1[7] = { 10, 20, 30, 40, 50, 60, 70 };
float glob2[7] = { 100, 200, 300, 400, 500, 600 };
void main() {
float i;
print(ftos(glob1[0]));
for (i = 1; i != 7; ++i)
print(" ", ftos(glob1[i]));
print("\n");
print(ftos(glob2[0]));
for (i = 1; i != 7; ++i)
print(" ", ftos(glob2[i]));
print("\n");
}

7
tests/arrays2.tmpl Normal file
View file

@ -0,0 +1,7 @@
I: arrays.qc
D: array accessors and functionality
T: -execute
C: -std=fteqcc
M: 1001 1101 1201 1301 1401 1501
M: 1001 1101 1201 1301 1401 1501 1601
M: 1001 1101 1201 1301 1401 1501