Skip to content

Commit

Permalink
Infer array length of inline allocated arrays
Browse files Browse the repository at this point in the history
Fixes bug 644046.
  • Loading branch information
flobrosch authored and lucabrunox committed Oct 25, 2014
1 parent f0b5b2d commit 0f0bca7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions vala/valalocalvariable.vala
Expand Up @@ -89,9 +89,18 @@ public class Vala.LocalVariable : Variable {
variable_type.check (context);
}

// Catch initializer list transformation:
bool is_initializer_list = false;
int initializer_size = -1;

if (initializer != null) {
initializer.target_type = variable_type;

if (initializer is InitializerList) {
initializer_size = ((InitializerList) initializer).size;
is_initializer_list = true;
}

initializer.check (context);
}

Expand Down Expand Up @@ -156,6 +165,20 @@ public class Vala.LocalVariable : Variable {
return false;
}


ArrayType variable_array_type = variable_type as ArrayType;
if (variable_array_type != null && variable_array_type.inline_allocated && !variable_array_type.fixed_length && is_initializer_list) {
variable_array_type.length = new IntegerLiteral (initializer_size.to_string ());
variable_array_type.fixed_length = true;
variable_array_type.nullable = false;
}

if (variable_array_type != null && variable_array_type.inline_allocated && initializer.value_type is ArrayType == false) {
error = true;
Report.error (source_reference, "only arrays are allowed as initializer for arrays with fixed length");
return false;
}

if (initializer.value_type.is_disposable ()) {
/* rhs transfers ownership of the expression */
if (!(variable_type is PointerType) && !variable_type.value_owned) {
Expand Down

0 comments on commit 0f0bca7

Please sign in to comment.