mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-23 12:22:26 +00:00
error about too many elements in initializer; added test for initialized arrays: arrays2.tmpl/qc
This commit is contained in:
parent
633d2ba8a4
commit
dc91918c1f
4 changed files with 36 additions and 5 deletions
10
ast.c
10
ast.c
|
@ -1212,6 +1212,16 @@ static bool ast_global_array_set(ast_value *self)
|
|||
size_t count = vec_size(self->initlist);
|
||||
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) {
|
||||
switch (self->expression.next->vtype) {
|
||||
case TYPE_FLOAT:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
I: arrays.qc
|
||||
D: array accessors and functionality
|
||||
I: arrays2.qc
|
||||
D: initialized arrays
|
||||
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
|
||||
M: 10 20 30 40 50 60 70
|
||||
M: 100 200 300 400 500 600 0
|
||||
|
|
15
tests/arrays2.qc
Normal file
15
tests/arrays2.qc
Normal 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
7
tests/arrays2.tmpl
Normal 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
|
Loading…
Reference in a new issue