[vala/staging] vala: Set error and return early on invalid index in ElementAccess
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Set error and return early on invalid index in ElementAccess
- Date: Tue, 18 Feb 2020 16:27:42 +0000 (UTC)
commit 94911d12799c38f95fa5c1a531304ec9c6f136fe
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Feb 18 16:35:21 2020 +0100
vala: Set error and return early on invalid index in ElementAccess
This caused criticals like:
vala_code_node_check: assertion 'self != NULL' failed
tests/Makefile.am | 1 +
tests/semantic/element-access-index-invalid.test | 6 ++++++
vala/valaelementaccess.vala | 3 +++
3 files changed, 10 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 98c5e5faf..9586b63ec 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -744,6 +744,7 @@ TESTS = \
semantic/delegate-return-valist.test \
semantic/delegate-too-few-type-arguments.test \
semantic/delegate-too-many-type-arguments.test \
+ semantic/element-access-index-invalid.test \
semantic/enum-empty.test \
semantic/errordomain-empty.test \
semantic/field-accessibility.test \
diff --git a/tests/semantic/element-access-index-invalid.test
b/tests/semantic/element-access-index-invalid.test
new file mode 100644
index 000000000..f653e8c92
--- /dev/null
+++ b/tests/semantic/element-access-index-invalid.test
@@ -0,0 +1,6 @@
+Invalid Code
+
+void main () {
+ int foo = 23;
+ var bar = foo["G"];
+}
diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala
index 9ecc6c67e..40a8c196b 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -195,8 +195,10 @@ public class Vala.ElementAccess : Expression {
}
if (array_type.rank < get_indices ().size) {
+ error = true;
Report.error (source_reference, "%d extra indices for element access".printf
(get_indices ().size - array_type.rank));
} else if (array_type.rank > get_indices ().size) {
+ error = true;
Report.error (source_reference, "%d missing indices for element
access".printf (array_type.rank - get_indices ().size));
}
} else if (pointer_type != null &&
!pointer_type.base_type.is_reference_type_or_type_parameter ()) {
@@ -229,6 +231,7 @@ public class Vala.ElementAccess : Expression {
error = true;
Report.error (source_reference, "The expression `%s' does not denote an array".printf
(container.value_type.to_string ()));
+ return false;
}
if (index_int_type_check) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]