]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Methods need to throw compatible error if target delegate throws one
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 26 Aug 2017 13:35:10 +0000 (15:35 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 24 Nov 2017 15:59:23 +0000 (16:59 +0100)
tests/Makefile.am
tests/delegates/delegates-error.test [new file with mode: 0644]
vala/valadelegate.vala

index c64a2cd013f0f47612a377100a87ef9d10098dc1..481575c09dad59e611627324bd59569a03994e3b 100644 (file)
@@ -160,6 +160,7 @@ TESTS = \
        structs/bug777194.vala \
        delegates/casting.vala \
        delegates/delegates.vala \
+       delegates/delegates-error.test \
        delegates/reference_transfer.vala \
        delegates/bug539166.vala \
        delegates/bug595610.vala \
diff --git a/tests/delegates/delegates-error.test b/tests/delegates/delegates-error.test
new file mode 100644 (file)
index 0000000..8d2a3ad
--- /dev/null
@@ -0,0 +1,17 @@
+Invalid Code
+
+delegate void FooFunc () throws Error;
+
+void foo (FooFunc func) {
+       try {
+               func ();
+       } catch (Error e) {
+       }
+}
+
+void bar_func () {
+}
+
+void main () {
+       foo (bar_func);
+}
index 356e6e141c1836901f64056efcf7807539da57d7..3e79527a8e4d23268bf495407d4c61c16982f8fb 100644 (file)
@@ -185,10 +185,18 @@ public class Vala.Delegate : TypeSymbol, Callable {
                        return false;
                }
 
+               var error_types = get_error_types ();
+               var method_error_types = m.get_error_types ();
+
+               // method must throw error if the delegate does
+               if (error_types.size > 0 && method_error_types.size == 0) {
+                       return false;
+               }
+
                // method may throw less but not more errors than the delegate
-               foreach (DataType method_error_type in m.get_error_types ()) {
+               foreach (DataType method_error_type in method_error_types) {
                        bool match = false;
-                       foreach (DataType delegate_error_type in get_error_types ()) {
+                       foreach (DataType delegate_error_type in error_types) {
                                if (method_error_type.compatible (delegate_error_type)) {
                                        match = true;
                                        break;