From: Rico Tzschichholz Date: Sat, 26 Aug 2017 13:35:10 +0000 (+0200) Subject: vala: Methods need to throw compatible error if target delegate throws one X-Git-Tag: 0.39.1~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0be7e312c45d0300af7bc88fdce3251387da9e39;p=thirdparty%2Fvala.git vala: Methods need to throw compatible error if target delegate throws one --- diff --git a/tests/Makefile.am b/tests/Makefile.am index c64a2cd01..481575c09 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..8d2a3adc3 --- /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 356e6e141..3e79527a8 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;