]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Really check compatiblity of error types for delegate symbol
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 21 Oct 2021 11:34:51 +0000 (13:34 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 21 Oct 2021 11:54:24 +0000 (13:54 +0200)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1242

tests/Makefile.am
tests/delegates/incompatible-error-assignment.test [new file with mode: 0644]
vala/valadelegatetype.vala

index 800bb6db86844542b7b4325b344921665a034ccc..209836d651ab0afe068f0fca3623d098c89e1485 100644 (file)
@@ -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 (file)
index 0000000..94b5c49
--- /dev/null
@@ -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;
+}
index 304da9eb25bb1c4fbdaf6ce6ee6828d43e8451d5..8b51f324cc0cf70ef16156b027e76095ed82825b 100644 (file)
@@ -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;