[vala/staging] vala: Check array type of declarations for errornous type-arguments
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Check array type of declarations for errornous type-arguments
- Date: Sun, 7 Mar 2021 13:32:24 +0000 (UTC)
commit 3f6bd8a3610e02f0c7d61239bd07bab176a6ea0d
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 5c9968256..7a52be5fc 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/array-too-few-type-arguments.test \
semantic/array-too-many-type-arguments.test \
semantic/assignment-element-incompatible-ownership.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]