]> 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 12:18:52 +0000 (14:18 +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 8ebd339949522e23ea38988f5848261b269ca6ab..116a582e2685068344ecbe97d0f34adf20830c2f 100644 (file)
@@ -407,6 +407,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 9d831954a13f63d19d35c652ddc5e95e938d438e..efe3181a82a053cbe5c021394c907f9ec92c7af1 100644 (file)
@@ -162,11 +162,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;