]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Check array type of declarations for errornous type-arguments
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 7 Mar 2021 13:20:43 +0000 (14:20 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 13 Mar 2021 20:33:12 +0000 (21:33 +0100)
tests/Makefile.am
tests/semantic/array-invalid-type-argument.test [new file with mode: 0644]
vala/valaarraytype.vala

index 4fc8abce089143e1b75bb8ece79d95d6b37bfd08..2180375e52d811581c60181b9532f00dc87f9417 100644 (file)
@@ -875,6 +875,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 (file)
index 0000000..89e6d40
--- /dev/null
@@ -0,0 +1,8 @@
+Invalid Code
+
+class Foo {
+}
+
+void main () {
+       Foo<string>[] foo = null;
+}
index c1ddb882984bce726597de303cc02a5241ce9a69..8b6dcf5ef46cfbee3e635ec53d008ffc9ab590ce 100644 (file)
@@ -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) {