]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: "_first_array" parameter for params-array is variadic too
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 2 Mar 2021 16:55:25 +0000 (17:55 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 13 Mar 2021 20:23:02 +0000 (21:23 +0100)
Not following this resulted in mismatching signature assumptions between
caller and callee if the callable throws an error.

codegen/valaccodemethodmodule.vala
tests/Makefile.am
tests/methods/params-array-with-throws.vala [new file with mode: 0644]

index 979eead1ab05b88eb9d216f3269b0b083eb2009e..2ec6b8899ac7f9a3fbe5bea449694ef7d48e3c19 100644 (file)
@@ -917,7 +917,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                }
 
                                cparam = new CCodeParameter ("_first_%s".printf (get_ccode_name (param)), ctypename);
-                               cparam_map.set (get_param_pos (get_ccode_pos (param), false), cparam);
+                               cparam_map.set (get_param_pos (get_ccode_pos (param) - 0.1, true), cparam);
 
                                va_list_name = "_va_list_%s".printf (get_ccode_name (param));
                        }
index cd125650b6045e6346287f15ee6eed5ca84e6274..043b2a825930862bbbcedeccbcd3e65dadc439dc 100644 (file)
@@ -222,6 +222,7 @@ TESTS = \
        methods/nowrapper-no-vfunc.test \
        methods/params-array.vala \
        methods/params-array-abstract.test \
+       methods/params-array-with-throws.vala \
        methods/print-attribute.vala \
        methods/print-attribute-invalid.test \
        methods/printf-invalid.test \
diff --git a/tests/methods/params-array-with-throws.vala b/tests/methods/params-array-with-throws.vala
new file mode 100644 (file)
index 0000000..9bffd66
--- /dev/null
@@ -0,0 +1,57 @@
+errordomain FooError {
+       BAD,
+       WORSE
+}
+
+void foo (params string[] array) throws FooError {
+       assert (array.length == 3);
+       assert (array[0] == "foo");
+       assert (array[1] == "bar");
+       assert (array[2] == "manam");
+}
+
+void bar (params string[] array) throws FooError {
+       throw new FooError.BAD ("bad");
+}
+
+class Foo {
+       public void foo (params string[] array) throws FooError {
+               assert (array.length == 3);
+               assert (array[0] == "foo");
+               assert (array[1] == "bar");
+               assert (array[2] == "manam");
+       }
+
+       public void bar (params string[] array) throws FooError {
+               throw new FooError.BAD ("bad");
+       }
+}
+
+void main () {
+       {
+               foo ("foo", "bar", "manam");
+       }
+       {
+               try {
+                       bar ("foo", "bar", "manam");
+                       assert_not_reached ();
+               } catch (FooError.BAD e) {
+               } catch {
+                       assert_not_reached ();
+               }
+       }
+       {
+               var foo = new Foo ();
+               foo.foo ("foo", "bar", "manam");
+       }
+       {
+               try {
+                       var foo = new Foo ();
+                       foo.bar ("foo", "bar", "manam");
+                       assert_not_reached ();
+               } catch (FooError.BAD e) {
+               } catch {
+                       assert_not_reached ();
+               }
+       }
+}