[vala/staging: 2/2] 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/staging: 2/2] vala: Methods need to throw compatible error if target delegate throws one
- Date: Fri, 24 Nov 2017 16:00:25 +0000 (UTC)
commit 0be7e312c45d0300af7bc88fdce3251387da9e39
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 c64a2cd..481575c 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 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 356e6e1..3e79527 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]