diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-02-25 12:35:15 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-03-25 13:02:55 +0100 |
commit | 74725956b2c99da3ff289ff2d294c525ff2f85c9 (patch) | |
tree | ee09c76f7301cb8013509219094b582b79fe4981 | |
parent | bd73f1ba11c387c919ad06d44badfd7065d1e35f (diff) | |
download | vala-74725956b2c99da3ff289ff2d294c525ff2f85c9.tar.gz |
codegen: Append initializer for "_*_size_" of array field in internal struct
Fixes https://gitlab.gnome.org/GNOME/vala/issues/914
-rw-r--r-- | codegen/valaccodebasemodule.vala | 3 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/arrays/struct-field-initializer.vala | 33 |
3 files changed, 37 insertions, 0 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 85ea40d5f..536aca2f6 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -2723,6 +2723,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { for (int dim = 1; dim <= array_type.rank; dim++) { clist.append (get_array_length_cvalue (expr.target_value, dim)); } + if (array_type.rank == 1 && field.is_internal_symbol ()) { + clist.append (get_array_length_cvalue (expr.target_value, 1)); + } } } diff --git a/tests/Makefile.am b/tests/Makefile.am index 0eaa2376a..7a6d37d8f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -90,6 +90,7 @@ TESTS = \ arrays/length-inline-assignment.vala \ arrays/length-type-include.vala \ arrays/struct-field-length-cname.vala \ + arrays/struct-field-initializer.vala \ arrays/incompatible-integer-elements.test \ arrays/slice-invalid-start.test \ arrays/slice-invalid-stop.test \ diff --git a/tests/arrays/struct-field-initializer.vala b/tests/arrays/struct-field-initializer.vala new file mode 100644 index 000000000..9534c8490 --- /dev/null +++ b/tests/arrays/struct-field-initializer.vala @@ -0,0 +1,33 @@ +[CCode (has_type_id = false)] +struct Foo { + public unowned string[] array; + public int i; +} + +[CCode (has_type_id = false)] +public struct Bar { + public unowned string[] array; + public int i; +} + +const string[] SARRAY = { "foo", "bar" }; + +const Foo FOO = { SARRAY, 23 }; +const Bar BAR = { SARRAY, 42 }; + +void main () { + { + assert (FOO.array.length == 2); + assert (FOO.i == 23); + assert (BAR.array.length == 2); + assert (BAR.i == 42); + } + { + const Foo foo = { SARRAY, 23 }; + const Bar bar = { SARRAY, 42 }; + assert (foo.array.length == 2); + assert (foo.i == 23); + assert (bar.array.length == 2); + assert (bar.i == 42); + } +} |