Inconsistent array declarations and definitions should lead to a warning or error
Currently a variety of combinations of array declarations are accepted while parts are silently ignored or overruled.
The Vala code:
void main() {
int[10] arr = {1};
stdout.printf("Length: %d\n", arr.length);
}
doesn't give any compilation error. C code:
void
_vala_main (void)
{
gint* arr = NULL;
gint* _tmp0_;
gint arr_length1;
gint _arr_size_;
FILE* _tmp1_;
_tmp0_ = g_new0 (gint, 1);
_tmp0_[0] = 1;
arr = _tmp0_;
arr_length1 = 1;
_arr_size_ = arr_length1;
_tmp1_ = stdout;
fprintf (_tmp1_, "Length: %d\n", arr_length1);
arr = (g_free (arr), NULL);
}
Using a size in that context shouldn't be allowed.
Trying to declare a function which takes an array as a parameter with the same type declaration:
void func(int[10] arr) {
}
however correctly results in a reasonable error message "syntax error, no expression allowed between array brackets" (for some reason the error message is duplicated).
Edited by Rico Tzschichholz