[vala/staging] vala: Don't allow move/resize of non-variable array references



commit 3a7942ef2d8693ea3bc9f414f76e5032bb6eb47d
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 2f52c3983..772932238 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -499,6 +499,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]