]> 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>
Tue, 29 Oct 2019 15:48:33 +0000 (16:48 +0100)
tests/Makefile.am
tests/arrays/fixed-length-resize-invalid.test [new file with mode: 0644]
vala/valamemberaccess.vala

index 775110cbb105b64a2ff1b297f721c0722142d116..4d2be1385f9a06d5d1a0c9c0ca13f8643acb00df 100644 (file)
@@ -76,6 +76,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 927e57531d2cdc0905b144b3433ce6bdcf732ee6..9316e5644e89a3ea79e569b8fa53a9ed579861c7 100644 (file)
@@ -452,6 +452,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