[vala/staging: 1/5] vala: Enforce required type-arguments on parameter/return types of callables




commit 661f08ea4d92c37a566b388c543240ac71cef6dd
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Aug 1 14:32:06 2022 +0200

    vala: Enforce required type-arguments on parameter/return types of callables
    
    This stricter check applies to delegate types in source files only.
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1342

 tests/Makefile.am                                 |  4 ++++
 tests/generics/delegate-return-type-missing.test  |  8 ++++++++
 tests/generics/method-parameter-type-missing.test |  9 +++++++++
 tests/generics/method-return-type-missing.test    | 10 ++++++++++
 tests/generics/signal-return-type-missing.test    | 10 ++++++++++
 vala/valadelegate.vala                            |  6 ++++++
 vala/valamethod.vala                              |  3 +++
 vala/valaparameter.vala                           |  3 +++
 vala/valasignal.vala                              |  6 ++++++
 9 files changed, 59 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 48e9d37d7..f5e0cb8ff 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -769,6 +769,7 @@ TESTS = \
        generics/arrays-not-supported-2.test \
        generics/arrays-not-supported-3.test \
        generics/constructor-chain-up.vala \
+       generics/delegate-return-type-missing.test \
        generics/floating-type-cast.vala \
        generics/gvariant-serialization.test \
        generics/inference-argument-may-fail.vala \
@@ -779,14 +780,17 @@ TESTS = \
        generics/parameter-invalid-initializer.test \
        generics/parameter-sizeof-initializer.vala \
        generics/member-dup-destroy.vala \
+       generics/method-parameter-type-missing.test \
        generics/method-parameter-unknown-type-parameter.test \
        generics/method-parameter-unknown-type-parameter-2.test \
+       generics/method-return-type-missing.test \
        generics/method-return-unknown-type-parameter.test \
        generics/method-return-unknown-type-parameter-2.test \
        generics/null-type.vala \
        generics/property-gobject-set.vala \
        generics/property-int-cast.vala \
        generics/reference-transfer.vala \
+       generics/signal-return-type-missing.test \
        generics/string-literal-comparison.vala \
        generics/type-parameter-properties.vala \
        generics/type-parameter-property-clash.vala \
diff --git a/tests/generics/delegate-return-type-missing.test 
b/tests/generics/delegate-return-type-missing.test
new file mode 100644
index 000000000..b2ab8fb95
--- /dev/null
+++ b/tests/generics/delegate-return-type-missing.test
@@ -0,0 +1,8 @@
+Invalid Code
+
+delegate T FooFunc<T> ();
+
+delegate FooFunc BarFunc ();
+
+void main () {
+}
diff --git a/tests/generics/method-parameter-type-missing.test 
b/tests/generics/method-parameter-type-missing.test
new file mode 100644
index 000000000..cc4197860
--- /dev/null
+++ b/tests/generics/method-parameter-type-missing.test
@@ -0,0 +1,9 @@
+Invalid Code
+
+delegate T FooFunc<T> ();
+
+void foo (FooFunc f) {
+}
+
+void main () {
+}
diff --git a/tests/generics/method-return-type-missing.test b/tests/generics/method-return-type-missing.test
new file mode 100644
index 000000000..313f53fae
--- /dev/null
+++ b/tests/generics/method-return-type-missing.test
@@ -0,0 +1,10 @@
+Invalid Code
+
+delegate T FooFunc<T> ();
+
+FooFunc bar () {
+       return null;
+}
+
+void main () {
+}
diff --git a/tests/generics/signal-return-type-missing.test b/tests/generics/signal-return-type-missing.test
new file mode 100644
index 000000000..35c77a1dd
--- /dev/null
+++ b/tests/generics/signal-return-type-missing.test
@@ -0,0 +1,10 @@
+Invalid Code
+
+delegate T FooFunc<T> ();
+
+class Foo {
+       public signal FooFunc bar ();
+}
+
+void main () {
+}
diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala
index eeaabcb69..cb53d2e91 100644
--- a/vala/valadelegate.vala
+++ b/vala/valadelegate.vala
@@ -319,6 +319,12 @@ public class Vala.Delegate : TypeSymbol, Callable {
                }
 
                return_type.check (context);
+               if (!external_package) {
+                       context.analyzer.check_type (return_type);
+                       if (return_type is DelegateType) {
+                               return_type.check_type_arguments (context);
+                       }
+               }
 
                if (return_type.type_symbol == context.analyzer.va_list_type.type_symbol) {
                        error = true;
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 2794cd48e..8c5c3af56 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -866,6 +866,9 @@ public class Vala.Method : Subroutine, Callable {
                return_type.check (context);
                if (!external_package) {
                        context.analyzer.check_type (return_type);
+                       if (return_type is DelegateType) {
+                               return_type.check_type_arguments (context);
+                       }
                }
 
                if (return_type.type_symbol == context.analyzer.va_list_type.type_symbol) {
diff --git a/vala/valaparameter.vala b/vala/valaparameter.vala
index 656188848..fb68ab069 100644
--- a/vala/valaparameter.vala
+++ b/vala/valaparameter.vala
@@ -208,6 +208,9 @@ public class Vala.Parameter : Variable {
                if (!ellipsis) {
                        if (!external_package) {
                                context.analyzer.check_type (variable_type);
+                               if (variable_type is DelegateType) {
+                                       variable_type.check_type_arguments (context);
+                               }
 
                                // check symbol availability
                                if ((parent_symbol == null || !parent_symbol.external_package) && 
variable_type.type_symbol != null) {
diff --git a/vala/valasignal.vala b/vala/valasignal.vala
index ffd5a760a..2b5005e3b 100644
--- a/vala/valasignal.vala
+++ b/vala/valasignal.vala
@@ -206,6 +206,12 @@ public class Vala.Signal : Symbol, Callable {
                }
 
                return_type.check (context);
+               if (!external_package) {
+                       context.analyzer.check_type (return_type);
+                       if (return_type is DelegateType) {
+                               return_type.check_type_arguments (context);
+                       }
+               }
 
                if (return_type.type_symbol == context.analyzer.va_list_type.type_symbol) {
                        error = true;


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