]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Check (optional) type-arguments of array creation expression
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 7 Mar 2021 12:42:16 +0000 (13:42 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 13 Mar 2021 20:33:12 +0000 (21:33 +0100)
tests/Makefile.am
tests/semantic/array-too-few-type-arguments.test [new file with mode: 0644]
tests/semantic/array-too-many-type-arguments.test [new file with mode: 0644]
vala/valaarraycreationexpression.vala

index 2180375e52d811581c60181b9532f00dc87f9417..a1a6ccba211b8716dc0730f2402632b17707a324 100644 (file)
@@ -876,6 +876,8 @@ TESTS = \
        semantic/array-incompatible-initializer.test \
        semantic/array-incompatible-initializer2.test \
        semantic/array-invalid-type-argument.test \
+       semantic/array-too-few-type-arguments.test \
+       semantic/array-too-many-type-arguments.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-too-few-type-arguments.test b/tests/semantic/array-too-few-type-arguments.test
new file mode 100644 (file)
index 0000000..3161b5b
--- /dev/null
@@ -0,0 +1,8 @@
+Invalid Code
+
+class Foo<G,T> {
+}
+
+void main () {
+       var foo = new Foo<string>[] {};
+}
diff --git a/tests/semantic/array-too-many-type-arguments.test b/tests/semantic/array-too-many-type-arguments.test
new file mode 100644 (file)
index 0000000..84d64e8
--- /dev/null
@@ -0,0 +1,8 @@
+Invalid Code
+
+class Foo<G> {
+}
+
+void main () {
+       var foo = new Foo<string,int>[] {};
+}
index 8af8fa8fe6cf044b4013d5b49ec323114147847d..c3a20adf9a1ef08cbbea76213164c17c687a8b3b 100644 (file)
@@ -245,6 +245,12 @@ public class Vala.ArrayCreationExpression : Expression {
 
                if (element_type != null) {
                        element_type.check (context);
+
+                       // check whether there is the expected amount of type-arguments
+                       if (!element_type.check_type_arguments (context, true)) {
+                               error = true;
+                               return false;
+                       }
                }
 
                if (length_type == null) {