]> 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>
Sun, 24 Oct 2021 10:14:42 +0000 (12:14 +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 d9c4b7a2e136d6eb5b96206d8ba8988a9dc1b578..8feb9a0a37507be3b1e7dab2f474d91f48cf5f92 100644 (file)
@@ -169,11 +169,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;