From: Rico Tzschichholz Date: Sun, 29 Sep 2019 19:25:43 +0000 (+0200) Subject: vala: Perform stricter compatibility check for delegates X-Git-Tag: 0.47.1~146 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=34f49f40c469384c82ef13af49a0882a8a07dda1;p=thirdparty%2Fvala.git vala: Perform stricter compatibility check for delegates This currently requires to consider compatible delegates as equal. --- diff --git a/tests/Makefile.am b/tests/Makefile.am index f6e4b0881..3efdffbba 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..5db2d1d66 --- /dev/null +++ b/tests/delegates/incompatible-target.test @@ -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 index 000000000..3280db414 --- /dev/null +++ b/tests/delegates/incompatible.test @@ -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 () { +} diff --git a/vala/valadelegatetype.vala b/vala/valadelegatetype.vala index 73155359d..0220b0168 100644 --- a/vala/valadelegatetype.vala +++ b/vala/valadelegatetype.vala @@ -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)