]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Perform stricter compatibility check for delegates 34f49f40c469384c82ef13af49a0882a8a07dda1
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 29 Sep 2019 19:25:43 +0000 (21:25 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 29 Sep 2019 19:56:38 +0000 (21:56 +0200)
This currently requires to consider compatible delegates as equal.

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

index f6e4b08819e04ff1daf239be5a5ce66f273b6323..3efdffbba81a779b09d50f50d21cf259dca069f4 100644 (file)
@@ -270,6 +270,8 @@ TESTS = \
        delegates/error-pos.vala \
        delegates/fields.vala \
        delegates/fields-no-target.vala \
+       delegates/incompatible.test \
+       delegates/incompatible-target.test \
        delegates/instance-method-to-no-target.test \
        delegates/lambda-mixed-instance-static.vala \
        delegates/lambda-shared-closure.vala \
diff --git a/tests/delegates/incompatible-target.test b/tests/delegates/incompatible-target.test
new file mode 100644 (file)
index 0000000..5db2d1d
--- /dev/null
@@ -0,0 +1,17 @@
+Invalid Code
+
+delegate void Func ();
+[CCode (has_target = false)]
+delegate void IncompatibleFunc ();
+
+interface Foo : Object {
+       public abstract void foo (Func? func);
+}
+
+class Bar : Object, Foo {
+       public void foo (IncompatibleFunc? func) {
+       }
+}
+
+void main () {
+}
diff --git a/tests/delegates/incompatible.test b/tests/delegates/incompatible.test
new file mode 100644 (file)
index 0000000..3280db4
--- /dev/null
@@ -0,0 +1,16 @@
+Invalid Code
+
+delegate void Func ();
+delegate void IncompatibleFunc (string s);
+
+interface Foo : Object {
+       public abstract void foo (Func? func);
+}
+
+class Bar : Object, Foo {
+       public void foo (IncompatibleFunc? func) {
+       }
+}
+
+void main () {
+}
index 73155359d77d904d7d69a0d8a8c3b0f0509dd3ec..0220b01680d7efbcee28549c8446eb2830fca57f 100644 (file)
@@ -108,6 +108,10 @@ public class Vala.DelegateType : CallableType {
                return result;
        }
 
+       public override bool equals (DataType type2) {
+               return compatible (type2);
+       }
+
        public override bool is_accessible (Symbol sym) {
                return delegate_symbol.is_accessible (sym);
        }
@@ -151,6 +155,10 @@ public class Vala.DelegateType : CallableType {
                        return true;
                }
 
+               if (delegate_symbol.has_target != dt_target.delegate_symbol.has_target) {
+                       return false;
+               }
+
                // target-delegate is allowed to ensure stricter return type (stronger postcondition)
                if (!get_return_type ().stricter (dt_target.get_return_type ().get_actual_type (dt_target, null, this))) {
                        return false;
@@ -171,9 +179,8 @@ public class Vala.DelegateType : CallableType {
                }
 
                foreach (Parameter param in dt_target.get_parameters ()) {
-                       /* target-delegate is allowed to accept less arguments */
                        if (!params_it.next ()) {
-                               break;
+                               return false;
                        }
 
                        // target-delegate is allowed to accept arguments of looser types (weaker precondition)