]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Do not allow to .resize() on arrays with fixed length
authorFlorian Brosch <flo.brosch@gmail.com>
Wed, 17 Sep 2014 12:49:00 +0000 (14:49 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 7 Nov 2019 11:11:48 +0000 (12:11 +0100)
tests/Makefile.am
tests/arrays/fixed-length-resize-invalid.test [new file with mode: 0644]
vala/valamemberaccess.vala

index ee3f8af2571429eeac8279a5350a43c78990bfd6..6cc135dac0c44092643481cd6726bbe23a55b176 100644 (file)
@@ -75,6 +75,7 @@ TESTS = \
        arrays/field-global-length-cname.vala \
        arrays/fixed-length-concat-invalid.test \
        arrays/fixed-length-non-const.test \
+       arrays/fixed-length-resize-invalid.test \
        arrays/struct-field-length-cname.vala \
        arrays/incompatible-integer-elements.test \
        arrays/slice-invalid-start.test \
diff --git a/tests/arrays/fixed-length-resize-invalid.test b/tests/arrays/fixed-length-resize-invalid.test
new file mode 100644 (file)
index 0000000..5386fd7
--- /dev/null
@@ -0,0 +1,6 @@
+Invalid Code
+
+void main () {
+       int foo[2] = { 23, 42 };
+       foo.resize (3);
+}
index 37eeafb875f27e53245009050a664df5cd2f91f8..cbf25177107fc870f35e994e014ce4cce90f3d0f 100644 (file)
@@ -447,6 +447,14 @@ public class Vala.MemberAccess : Expression {
                                        may_access_klass_members = true;
                                }
                        }
+
+                       if (symbol_reference is ArrayResizeMethod && inner.value_type is ArrayType) {
+                               unowned ArrayType? value_array_type = inner.value_type as ArrayType;
+                               if (value_array_type != null && value_array_type.inline_allocated) {
+                                       Report.error (source_reference, "`resize' is not supported for arrays with fixed length");
+                                       error = true;
+                               }
+                       }
                }
 
                // enum-type inference