[vala/0.44] vala: Infer array length of inline allocated arrays for fields



commit 1866547a532a307cb440afa26b89299bf41aa682
Author: Florian Brosch <flo brosch gmail com>
Date:   Thu Sep 18 05:09:03 2014 +0200

    vala: Infer array length of inline allocated arrays for fields
    
    Don't allow non-arrays as initializer for inline allocated arrays
    
    Same as 0f0bca7e0519af13d9217fbca2c20ce67cd3baba
    
    See https://bugzilla.gnome.org/show_bug.cgi?id=644046

 vala/valafield.vala | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
---
diff --git a/vala/valafield.vala b/vala/valafield.vala
index 6bd54ff95..715d60935 100644
--- a/vala/valafield.vala
+++ b/vala/valafield.vala
@@ -117,6 +117,15 @@ public class Vala.Field : Variable, Lockable {
                if (initializer != null) {
                        initializer.target_type = variable_type;
 
+                       // Catch initializer list transformation:
+                       bool is_initializer_list = false;
+                       int initializer_size = -1;
+
+                       if (initializer is InitializerList) {
+                               initializer_size = ((InitializerList) initializer).size;
+                               is_initializer_list = true;
+                       }
+
                        if (!initializer.check (context)) {
                                error = true;
                                return false;
@@ -134,6 +143,18 @@ public class Vala.Field : Variable, Lockable {
                                return false;
                        }
 
+                       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)) {
+                               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) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]