[vala/staging] codegen: "_first_array" parameter for params-array is variadic too
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: "_first_array" parameter for params-array is variadic too
- Date: Thu, 4 Mar 2021 07:15:23 +0000 (UTC)
commit 08445b3c0e72de8acfb0c32622c9a070155db9d4
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Mar 2 17:55:25 2021 +0100
codegen: "_first_array" parameter for params-array is variadic too
Not following this resulted in mismatching signature assumptions between
caller and callee if the callable throws an error.
codegen/valaccodemethodmodule.vala | 2 +-
tests/Makefile.am | 1 +
tests/methods/params-array-with-throws.vala | 57 +++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 1cc2e53b5..d04f54a88 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -913,7 +913,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));
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 07815e81d..03b3e5647 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -223,6 +223,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
index 000000000..9bffd6680
--- /dev/null
+++ b/tests/methods/params-array-with-throws.vala
@@ -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 ();
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]