[vala/staging] vala: Really check compatiblity of error types for delegate symbol




commit 01b87299042d891d61bea9966b98e0de6d156c58
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Oct 21 13:34:51 2021 +0200

    vala: Really check compatiblity of error types for delegate symbol
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1242

 tests/Makefile.am                                  |  1 +
 tests/delegates/incompatible-error-assignment.test | 18 ++++++++++++++++++
 vala/valadelegatetype.vala                         |  4 ++--
 3 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 800bb6db8..209836d65 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -413,6 +413,7 @@ TESTS = \
        delegates/implicit-local-variable.vala \
        delegates/incompatible.test \
        delegates/incompatible-assignment.test \
+       delegates/incompatible-error-assignment.test \
        delegates/incompatible-initializer.test \
        delegates/incompatible-target.test \
        delegates/instance-method-to-no-target.test \
diff --git a/tests/delegates/incompatible-error-assignment.test 
b/tests/delegates/incompatible-error-assignment.test
new file mode 100644
index 000000000..94b5c492a
--- /dev/null
+++ b/tests/delegates/incompatible-error-assignment.test
@@ -0,0 +1,18 @@
+Invalid Code
+
+errordomain FooError {
+       FAIL;
+}
+
+errordomain BarError {
+       FAIL;
+}
+
+delegate void FooFunc () throws FooError;
+
+delegate void BarFunc () throws BarError;
+
+void main () {
+       FooFunc f = () => { throw new FooError.FAIL (""); };
+       BarFunc b = f;
+}
diff --git a/vala/valadelegatetype.vala b/vala/valadelegatetype.vala
index 304da9eb2..8b51f324c 100644
--- a/vala/valadelegatetype.vala
+++ b/vala/valadelegatetype.vala
@@ -168,11 +168,11 @@ public class Vala.DelegateType : CallableType {
 
                // target-delegate may throw less but not more errors than the delegate
                var error_types = new ArrayList<DataType> ();
-               get_error_types (error_types);
+               delegate_symbol.get_error_types (error_types);
                foreach (DataType error_type in error_types) {
                        bool match = false;
                        var delegate_error_types = new ArrayList<DataType> ();
-                       dt_target.get_error_types (delegate_error_types);
+                       dt_target.delegate_symbol.get_error_types (delegate_error_types);
                        foreach (DataType delegate_error_type in delegate_error_types) {
                                if (error_type.compatible (delegate_error_type)) {
                                        match = true;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]