summaryrefslogtreecommitdiff
path: root/tests/delegates
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-01-10 09:55:11 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2019-01-10 12:44:45 +0100
commitb2fd797bdfc8ee825c64b80b70d1c526472758ac (patch)
treeb62d9979734429b17a2fc40ae5b3033f7cf84965 /tests/delegates
parent704188bf81302862a45ed1b9a4ac336225598e50 (diff)
downloadvala-b2fd797bdfc8ee825c64b80b70d1c526472758ac.tar.gz
codegen: Add "error_pos" CCode attribute and use it as needed
This makes it possible to use non-standard error parameter positions within the vala source. Fixes https://gitlab.gnome.org/GNOME/vala/issues/728
Diffstat (limited to 'tests/delegates')
-rw-r--r--tests/delegates/error-pos.vala47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/delegates/error-pos.vala b/tests/delegates/error-pos.vala
new file mode 100644
index 000000000..2e9301a68
--- /dev/null
+++ b/tests/delegates/error-pos.vala
@@ -0,0 +1,47 @@
+errordomain FooError {
+ BAR;
+}
+
+[CCode (error_pos = 1.8, instance_pos = 1.9)]
+delegate string FooFunc (int i) throws FooError;
+
+class Bar {
+ [CCode (error_pos = 0.8)]
+ public string foo (int i) throws FooError {
+ assert (this is Bar);
+ return "%i".printf (i);
+ }
+
+ [CCode (error_pos = 0.8)]
+ public string faz (int i) throws FooError {
+ assert (this is Bar);
+ throw new FooError.BAR ("%i".printf (i));
+ }
+}
+
+void foo (FooFunc f) {
+ try {
+ assert (f (23) == "23");
+ } catch {
+ assert_not_reached ();
+ }
+}
+
+void main () {
+ try {
+ var bar = new Bar ();
+ assert (bar.foo (42) == "42");
+ foo (bar.foo);
+ } catch {
+ assert_not_reached ();
+ }
+
+ try {
+ var bar = new Bar ();
+ bar.faz (42);
+ } catch (FooError.BAR e) {
+ assert (e.message == "42");
+ } catch {
+ assert_not_reached ();
+ }
+}