[vala/staging: 1/2] vala: Check delegate type parameter parity



commit 018b85240e9441f9c22158acc9434a83ee98bfcf
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/asynchronous/bug598697.vala |    2 ++
 tests/delegates/bug772204.test    |    7 +++++++
 tests/methods/bug596726.vala      |    2 ++
 tests/objects/bug596621.vala      |    2 ++
 vala/valadelegatetype.vala        |   18 +++++++++++++++++-
 6 files changed, 31 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/asynchronous/bug598697.vala b/tests/asynchronous/bug598697.vala
index 804039a..24d310e 100644
--- a/tests/asynchronous/bug598697.vala
+++ b/tests/asynchronous/bug598697.vala
@@ -1,3 +1,5 @@
+delegate void Func ();
+
 public class Foo {
        public async void do_foo () {
                Func f = () => {};
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/tests/methods/bug596726.vala b/tests/methods/bug596726.vala
index 6eaec26..2203ece 100644
--- a/tests/methods/bug596726.vala
+++ b/tests/methods/bug596726.vala
@@ -1,3 +1,5 @@
+delegate void Func ();
+
 void do_bar (Func f) {
 }
 
diff --git a/tests/objects/bug596621.vala b/tests/objects/bug596621.vala
index 348ea40..8a732f1 100644
--- a/tests/objects/bug596621.vala
+++ b/tests/objects/bug596621.vala
@@ -1,3 +1,5 @@
+delegate void Func ();
+
 class Foo : Object {
        [CCode (has_construct_function = false)]
        public Foo () {
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]