[vala/wip/generics: 3/4] vala: Check delegate type parameter parity



commit 3d578aa34357ef3e84b78e87ee7ace1eac295adb
Author: Matthias Berndt <matthias_berndt gmx de>
Date:   Thu Sep 29 23:27:21 2016 +0200

    vala: Check delegate type parameter parity
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772204

 tests/Makefile.am              |    1 +
 tests/delegates/bug772204.test |    7 +++++++
 vala/valadelegatetype.vala     |   18 +++++++++++++++++-
 3 files changed, 25 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e10be4d..8341c09 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -131,6 +131,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..5c4e3a0
--- /dev/null
+++ b/tests/delegates/bug772204.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+delegate void foo<T> ();
+
+void main () {
+       foo f = null;
+}
diff --git a/vala/valadelegatetype.vala b/vala/valadelegatetype.vala
index 11ba57f..62860d4 100644
--- a/vala/valadelegatetype.vala
+++ b/vala/valadelegatetype.vala
@@ -113,10 +113,26 @@ public class Vala.DelegateType : DataType {
        }
 
        public override bool check (CodeContext context) {
+               if (checked) {
+                       return !error;
+               }
+
+               error = false;
+
                if (is_called_once && !value_owned) {
                        Report.warning (source_reference, "delegates with scope=\"async\" must be owned");
                }
-               return delegate_symbol.check (context);
+
+               var n_type_params = delegate_symbol.get_type_parameters ().size;
+               var n_type_args = get_type_arguments ().size;
+               if (n_type_args != n_type_params) {
+                       Report.error (source_reference, "%d type parameter(s) required, %d given".printf 
(n_type_params, n_type_args));
+                       error = true;
+               }
+
+               error = error || !delegate_symbol.check (context);
+               checked = true;
+               return !error;
        }
 
        public override bool is_disposable () {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]