]> 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>
Mon, 16 Apr 2018 19:02:17 +0000 (21:02 +0200)
codegen/valaccodebasemodule.vala
tests/basic-types/arrays.vala

index d8a6329937433dddc92df7e37a1561073b9dcfe7..6df6714adee0df3c2a5c5faeddbdedaedea26a94 100644 (file)
@@ -2518,7 +2518,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 fece74999a97d2811dacd0bb2fd30054dbf6b106..0bb70485ef600acb2dde7d1f15b6757dfcf8e20e 100644 (file)
@@ -191,6 +191,19 @@ void test_void_array () {
        assert ((void*) null in a);
 }
 
+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 ();
@@ -202,4 +215,5 @@ void main () {
        test_delegate_array ();
        test_generics_array ();
        test_void_array ();
+       test_struct_array ();
 }