[vala/staging] vala: Check type-arguments of array creation
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Check type-arguments of array creation
- Date: Sun, 7 Mar 2021 12:44:17 +0000 (UTC)
commit 7317dd9ec71de144e9090583bd576fa905f03a96
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Mar 7 13:42:16 2021 +0100
vala: Check type-arguments of array creation
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1147
tests/Makefile.am | 2 ++
tests/semantic/array-too-few-type-arguments.test | 8 ++++++++
tests/semantic/array-too-many-type-arguments.test | 8 ++++++++
vala/valaarraycreationexpression.vala | 6 ++++++
4 files changed, 24 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 32bd92fc5..5c9968256 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -887,6 +887,8 @@ TESTS = \
semantic/array-stacked.test \
semantic/array-incompatible-initializer.test \
semantic/array-incompatible-initializer2.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
index 000000000..1ebd09e21
--- /dev/null
+++ b/tests/semantic/array-too-few-type-arguments.test
@@ -0,0 +1,8 @@
+Invalid Code
+
+class Foo<G> {
+}
+
+void main () {
+ var foo = new Foo[] {};
+}
diff --git a/tests/semantic/array-too-many-type-arguments.test
b/tests/semantic/array-too-many-type-arguments.test
new file mode 100644
index 000000000..84d64e83f
--- /dev/null
+++ b/tests/semantic/array-too-many-type-arguments.test
@@ -0,0 +1,8 @@
+Invalid Code
+
+class Foo<G> {
+}
+
+void main () {
+ var foo = new Foo<string,int>[] {};
+}
diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala
index fdc2eef8d..7bedfcbf2 100644
--- a/vala/valaarraycreationexpression.vala
+++ b/vala/valaarraycreationexpression.vala
@@ -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)) {
+ error = true;
+ return false;
+ }
}
if (length_type == null) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]