diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-03-07 14:20:43 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-03-07 16:29:51 +0100 |
commit | 07c1f094fea124921589f77a3560a96e5ebbe86b (patch) | |
tree | 2301939956b90ec17bf2e6bdacd7e5cc989944f3 | |
parent | 865bafbc7e3aadbc13193919873686407af68a78 (diff) | |
download | vala-07c1f094fea124921589f77a3560a96e5ebbe86b.tar.gz |
vala: Check array type of declarations for errornous type-arguments
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/semantic/array-invalid-type-argument.test | 8 | ||||
-rw-r--r-- | vala/valaarraytype.vala | 13 |
3 files changed, 21 insertions, 1 deletions
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) { |