]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Fix params-array in constructor for struct
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 15 Jul 2021 10:35:41 +0000 (12:35 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 22 Jul 2021 08:59:40 +0000 (10:59 +0200)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1202

codegen/valaccodearraymodule.vala
tests/Makefile.am
tests/structs/constructor-params-array.vala [new file with mode: 0644]

index 9bfe9db5927941129645c8626d8beff074d54cbc..e6d694be5ad2272585fca7b2d4a0445bcdb4f5c1 100644 (file)
@@ -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))));
index cff8492b0e268ee8f854b854739f1d469578e679..7d7a68da6ec643e3b7c593b72be630cb954a3148 100644 (file)
@@ -340,6 +340,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 (file)
index 0000000..585be83
--- /dev/null
@@ -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");
+}