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



commit 15011c46b0b26bfa4faee75620e769bd648771d1
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 9bfe9db59..e6d694be5 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -915,7 +915,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 68340c3f2..da1e63b0c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -339,6 +339,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]