]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't append fixed-length of array fields in initializers
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 15 Feb 2018 17:07:36 +0000 (18:07 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 15 Feb 2018 17:09:32 +0000 (18:09 +0100)
codegen/valaccodebasemodule.vala
tests/basic-types/arrays.vala

index 56e12c65d3a72e20ca09aa5340470a7660eb86d2..19174d14dd25691ba2130c8209c462a02e91db0b 100644 (file)
@@ -2545,7 +2545,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                        clist.append (cexpr);
 
                                        var array_type = field.variable_type as ArrayType;
-                                       if (array_type != null && get_ccode_array_length (field) && !get_ccode_array_null_terminated (field)) {
+                                       if (array_type != null && !array_type.fixed_length && get_ccode_array_length (field) && !get_ccode_array_null_terminated (field)) {
                                                for (int dim = 1; dim <= array_type.rank; dim++) {
                                                        clist.append (get_array_length_cvalue (expr.target_value, dim));
                                                }
index 4f821d94dac9bdf1ff7f5579a3e13f1404558736..b749bdcb27cd8788933b95245491f54b77d7b131 100644 (file)
@@ -241,6 +241,19 @@ void test_array_resize () {
        assert (a[a.length - 1] == 5);
 }
 
+struct Foo {
+       unowned string array[2];
+       int bar;
+}
+
+const Foo[] FOO_ARRAY_CONST = {
+       { { "foo", "bar" }, 42 },
+};
+
+void test_struct_array () {
+       assert (FOO_ARRAY_CONST[0].bar == 42);
+}
+
 void main () {
        test_integer_array ();
        test_string_array ();
@@ -256,4 +269,5 @@ void main () {
        test_explicit_copying ();
        test_array_move ();
        test_array_resize ();
+       test_struct_array ();
 }