[vala/0.52] codegen: Fix params-array in constructor for struct



commit e6568b4b1deb005c42052bb8ff0b62ae5d88e83a
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Jul 15 12:35:41 2021 +0200

    codegen: Fix params-array in constructor for struct
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1202

 codegen/valaccodearraymodule.vala           |  2 +-
 tests/Makefile.am                           |  1 +
 tests/structs/constructor-params-array.vala | 16 ++++++++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 7d23b8143..e9a8b0701 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -921,7 +921,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                        cfile.add_include ("stdarg.h");
                }
 
-               if (!(m is CreationMethod)) {
+               if (!(m is CreationMethod) || m.parent_symbol is Struct) {
                        ccode.add_declaration ("va_list", new CCodeVariableDeclarator ("_va_list_%s".printf 
(get_ccode_name (local))));
                        var vastart = new CCodeFunctionCall (new CCodeIdentifier ("va_start"));
                        vastart.add_argument (new CCodeIdentifier ("_va_list_%s".printf (get_ccode_name 
(local))));
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 12c77bfee..43d990bc5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -342,6 +342,7 @@ TESTS = \
        structs/struct-static-field-initializer.test \
        structs/struct-static-property-initializer.test \
        structs/structs.vala \
+       structs/constructor-params-array.vala \
        structs/constructor-variadic.vala \
        structs/constructor-wrong-name.test \
        structs/default-gtype.vala \
diff --git a/tests/structs/constructor-params-array.vala b/tests/structs/constructor-params-array.vala
new file mode 100644
index 000000000..585be83a9
--- /dev/null
+++ b/tests/structs/constructor-params-array.vala
@@ -0,0 +1,16 @@
+struct Foo {
+       public string[] sa;
+
+       public Foo (params string[] strv) {
+               assert (strv.length == 3);
+               assert (strv[0] == "foo");
+               assert (strv[1] == "bar");
+               assert (strv[2] == "manam");
+               sa = strv;
+       }
+}
+
+void main () {
+       var foo = Foo ("foo", "bar", "manam");
+       assert (foo.sa[1] == "bar");
+}


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