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



commit e2be8ff74edd86606c4915d2e4b8e7caa0c4b844
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 91fae4289..3394d922b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -855,6 +855,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 588539c12..7fff66b04 100644
--- a/vala/valaarraytype.vala
+++ b/vala/valaarraytype.vala
@@ -324,7 +324,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]