From: Matthias Berndt Date: Thu, 29 Sep 2016 21:27:21 +0000 (+0200) Subject: vala: Check generic-types count of DelegateType X-Git-Tag: 0.35.2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03a2baee6383c2b14542719734ed4e3a6376b709;p=thirdparty%2Fvala.git vala: Check generic-types count of DelegateType https://bugzilla.gnome.org/show_bug.cgi?id=772204 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 9df9790e2..0eb96a393 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -139,6 +139,7 @@ TESTS = \ delegates/bug659778.vala \ delegates/bug703804.vala \ delegates/bug761360.vala \ + delegates/bug772204.test \ objects/chainup.vala \ objects/classes.vala \ objects/generics.vala \ diff --git a/tests/delegates/bug772204.test b/tests/delegates/bug772204.test new file mode 100644 index 000000000..0cd0e5672 --- /dev/null +++ b/tests/delegates/bug772204.test @@ -0,0 +1,7 @@ +Invalid Code + +delegate void Foo (); + +void main () { + Foo f = null; +} diff --git a/vala/valadelegatetype.vala b/vala/valadelegatetype.vala index 11ba57f00..221688dd8 100644 --- a/vala/valadelegatetype.vala +++ b/vala/valadelegatetype.vala @@ -116,7 +116,28 @@ public class Vala.DelegateType : DataType { if (is_called_once && !value_owned) { Report.warning (source_reference, "delegates with scope=\"async\" must be owned"); } - return delegate_symbol.check (context); + + if (!delegate_symbol.check (context)) { + return false; + } + + var n_type_params = delegate_symbol.get_type_parameters ().size; + var n_type_args = get_type_arguments ().size; + if (n_type_args > 0 && n_type_args < n_type_params) { + Report.error (source_reference, "too few type arguments"); + return false; + } else if (n_type_args > 0 && n_type_args > n_type_params) { + Report.error (source_reference, "too many type arguments"); + return false; + } + + foreach (DataType type in get_type_arguments ()) { + if (!type.check (context)) { + return false; + } + } + + return true; } public override bool is_disposable () {