[vala/staging: 2/2] vala: Don't allow move/resize of non-variable array references
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 2/2] vala: Don't allow move/resize of non-variable array references
- Date: Fri, 3 Jul 2020 17:55:14 +0000 (UTC)
commit 570e979e4f89482a75f1e6ef0e96f58a3e95a76b
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Fri Jul 3 19:33:41 2020 +0200
vala: Don't allow move/resize of non-variable array references
See https://gitlab.gnome.org/GNOME/vala/issues/928
tests/Makefile.am | 2 ++
tests/arrays/move-context-invalid.test | 9 +++++++++
tests/arrays/resize-context-invalid.test | 9 +++++++++
vala/valamemberaccess.vala | 6 ++++++
4 files changed, 26 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index da440e248..bf8e02f77 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -96,11 +96,13 @@ TESTS = \
arrays/in-operator-with-boxed-needle.vala \
arrays/length-inline-assignment.vala \
arrays/length-type-include.vala \
+ arrays/move-context-invalid.test \
arrays/struct-field-length-cname.vala \
arrays/struct-field-initializer.vala \
arrays/struct-namespaced-initializer.vala \
arrays/incompatible-integer-elements.test \
arrays/resize.vala \
+ arrays/resize-context-invalid.test \
arrays/resize-unowned-invalid.test \
arrays/resize-unowned-invalid-2.test \
arrays/resize-unowned-invalid-3.test \
diff --git a/tests/arrays/move-context-invalid.test b/tests/arrays/move-context-invalid.test
new file mode 100644
index 000000000..6f083e229
--- /dev/null
+++ b/tests/arrays/move-context-invalid.test
@@ -0,0 +1,9 @@
+Invalid Code
+
+string[] get_foo () {
+ return new string[23];
+}
+
+void main () {
+ get_foo ().move (5, 0, 1);
+}
diff --git a/tests/arrays/resize-context-invalid.test b/tests/arrays/resize-context-invalid.test
new file mode 100644
index 000000000..e85e5ea99
--- /dev/null
+++ b/tests/arrays/resize-context-invalid.test
@@ -0,0 +1,9 @@
+Invalid Code
+
+string[] get_foo () {
+ return new string[23];
+}
+
+void main () {
+ get_foo ().resize (42);
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index db022fefd..5fc45b283 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -498,6 +498,12 @@ public class Vala.MemberAccess : Expression {
error = true;
}
}
+
+ if ((symbol_reference is ArrayMoveMethod || symbol_reference is ArrayResizeMethod)
+ && !(inner.symbol_reference is Variable)) {
+ Report.error (source_reference, "`move' or `resize' is not allowed for array
in this context");
+ error = true;
+ }
}
// enum-type inference
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]