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



commit 680930f64b34daa47f6224b105aa92a4c2fff77d
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 56e12c6..19174d1 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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));
                                                }
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]