[vala/staging] vala: Accept NullType as generic type argument



commit fe3625d89f2511063e95d8cd3f4e30eb083021c5
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Sep 26 13:49:51 2021 +0200

    vala: Accept NullType as generic type argument

 tests/Makefile.am              |  1 +
 tests/generics/null-type.vala  | 10 ++++++++++
 vala/valasemanticanalyzer.vala |  1 +
 3 files changed, 12 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f77a696f5..cb1ac9fe8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -709,6 +709,7 @@ TESTS = \
        generics/parameter-invalid-initializer.test \
        generics/parameter-sizeof-initializer.vala \
        generics/member-dup-destroy.vala \
+       generics/null-type.vala \
        generics/property-int-cast.vala \
        generics/reference-transfer.vala \
        generics/string-literal-comparison.vala \
diff --git a/tests/generics/null-type.vala b/tests/generics/null-type.vala
new file mode 100644
index 000000000..a427ee8c1
--- /dev/null
+++ b/tests/generics/null-type.vala
@@ -0,0 +1,10 @@
+void foo<T> (T t) {
+       assert (t == null);
+       assert (typeof (T) == Type.INVALID);
+       assert (T.dup == null);
+       assert (T.destroy == null);
+}
+
+void main () {
+       foo (null);
+}
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index 016f2ef02..7f2e56c03 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -1311,6 +1311,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
 
        void check_type_argument (DataType type_arg) {
                if (type_arg is GenericType
+                   || type_arg is NullType
                    || type_arg is PointerType
                    || type_arg is VoidType
                    || is_reference_type_argument (type_arg)


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