[vala/0.38] codegen: Don't append fixed-length of array fields in initializers



commit a842f2e5e40addcc7831bbf715cfedfc7ba481a1
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Feb 15 18:07:36 2018 +0100

    codegen: Don't append fixed-length of array fields in initializers

 codegen/valaccodebasemodule.vala |    2 +-
 tests/basic-types/arrays.vala    |   14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 814057e..18aeea9 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2538,7 +2538,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));
                                                }
diff --git a/tests/basic-types/arrays.vala b/tests/basic-types/arrays.vala
index 4f821d9..b749bdc 100644
--- a/tests/basic-types/arrays.vala
+++ b/tests/basic-types/arrays.vala
@@ -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 ();
 }


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