[vala/staging] vala: Check array type of declarations for errornous type-arguments



commit 07c1f094fea124921589f77a3560a96e5ebbe86b
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Mar 7 14:20:43 2021 +0100

    vala: Check array type of declarations for errornous type-arguments

 tests/Makefile.am                               |  1 +
 tests/semantic/array-invalid-type-argument.test |  8 ++++++++
 vala/valaarraytype.vala                         | 13 ++++++++++++-
 3 files changed, 21 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 32bd92fc5..98d4e386a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -887,6 +887,7 @@ TESTS = \
        semantic/array-stacked.test \
        semantic/array-incompatible-initializer.test \
        semantic/array-incompatible-initializer2.test \
+       semantic/array-invalid-type-argument.test \
        semantic/assignment-element-incompatible-ownership.test \
        semantic/assignment-element-incompatible-type.test \
        semantic/assignment-fixed-array-length.test \
diff --git a/tests/semantic/array-invalid-type-argument.test b/tests/semantic/array-invalid-type-argument.test
new file mode 100644
index 000000000..89e6d4039
--- /dev/null
+++ b/tests/semantic/array-invalid-type-argument.test
@@ -0,0 +1,8 @@
+Invalid Code
+
+class Foo {
+}
+
+void main () {
+       Foo<string>[] foo = null;
+}
diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala
index 44b01b0f2..2468edf20 100644
--- a/vala/valaarraytype.vala
+++ b/vala/valaarraytype.vala
@@ -326,7 +326,18 @@ public class Vala.ArrayType : ReferenceType {
                        }
                }
 
-               return element_type.check (context);
+               if (!element_type.check (context)) {
+                       error = true;
+                       return false;
+               }
+
+               // check whether there is the expected amount of type-arguments
+               if (!element_type.check_type_arguments (context, true)) {
+                       error = true;
+                       return false;
+               }
+
+               return true;
        }
 
        public override DataType get_actual_type (DataType? derived_instance_type, List<DataType>? 
method_type_arguments, CodeNode? node_reference) {


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