]> 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>
Mon, 19 Jul 2021 13:04:48 +0000 (15:04 +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 7d23b8143388b2c351c161961f81f268b42b395d..e9a8b0701cc839166f9d18f66640cb1b3da49019 100644 (file)
@@ -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))));
index 12c77bfee6a0fc9c9e3a2ea4ffc30fc89bfa2cd0..43d990bc5eccbf4366688600e917fda88063ff76 100644 (file)
@@ -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 (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");
+}