[vala/staging: 1/2] vala: Check generic-types count of DelegateType
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 1/2] vala: Check generic-types count of DelegateType
- Date: Sat, 10 Dec 2016 10:08:46 +0000 (UTC)
commit 03a2baee6383c2b14542719734ed4e3a6376b709
Author: Matthias Berndt <matthias_berndt gmx de>
Date: Thu Sep 29 23:27:21 2016 +0200
vala: Check generic-types count of DelegateType
https://bugzilla.gnome.org/show_bug.cgi?id=772204
tests/Makefile.am | 1 +
tests/delegates/bug772204.test | 7 +++++++
vala/valadelegatetype.vala | 23 ++++++++++++++++++++++-
3 files changed, 30 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9df9790..0eb96a3 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 0000000..0cd0e56
--- /dev/null
+++ b/tests/delegates/bug772204.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+delegate void Foo<T,V> ();
+
+void main () {
+ Foo<int> f = null;
+}
diff --git a/vala/valadelegatetype.vala b/vala/valadelegatetype.vala
index 11ba57f..221688d 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 () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]