[vala/wip/callabletype: 1/3] vala: Methods need to throw compatible	error if target delegate throws one
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc: 
- Subject: [vala/wip/callabletype: 1/3] vala: Methods need to throw compatible	error if target delegate throws one
- Date: Sat,  2 Sep 2017 18:25:06 +0000 (UTC)
commit 92b8dcdf10be1ea393f418c2b4fdf6b55cdaf391
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Aug 26 15:35:10 2017 +0200
    vala: Methods need to throw compatible error if target delegate throws one
 tests/Makefile.am                    |    1 +
 tests/delegates/delegates-error.test |   17 +++++++++++++++++
 vala/valadelegate.vala               |   12 ++++++++++--
 3 files changed, 28 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b3e5f7c..3b75a31 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -156,6 +156,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
index 0000000..8d2a3ad
--- /dev/null
+++ b/tests/delegates/delegates-error.test
@@ -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);
+}
diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala
index 6f4ae3b..3d8a55e 100644
--- a/vala/valadelegate.vala
+++ b/vala/valadelegate.vala
@@ -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;
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]