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

index 0280645452303947ca92274178d921dac5038631..ee3f8af2571429eeac8279a5350a43c78990bfd6 100644 (file)
@@ -73,6 +73,7 @@ TESTS = \
        arrays/class-field-length-cname.vala \
        arrays/expression-bracket.test \
        arrays/field-global-length-cname.vala \
+       arrays/fixed-length-concat-invalid.test \
        arrays/fixed-length-non-const.test \
        arrays/struct-field-length-cname.vala \
        arrays/incompatible-integer-elements.test \
diff --git a/tests/arrays/fixed-length-concat-invalid.test b/tests/arrays/fixed-length-concat-invalid.test
new file mode 100644 (file)
index 0000000..99f24a3
--- /dev/null
@@ -0,0 +1,6 @@
+Invalid Code
+
+void main () {
+       int foo[2] = { 23, 42 };
+       foo += 4711;
+}
index 5e9b7be42754d34faf0601d17aa867cc1a6449f6..32d5012b57ceb9d820ee1b5ca29c5012724411d4 100644 (file)
@@ -343,6 +343,10 @@ public class Vala.BinaryExpression : Expression {
 
                        var array_type = (ArrayType) left.value_type;
 
+                       if (array_type.inline_allocated) {
+                               error = true;
+                               Report.error (source_reference, "Array concatenation not supported for fixed length arrays");
+                       }
                        if (right.value_type == null || !right.value_type.compatible (array_type.element_type)) {
                                error = true;
                                Report.error (source_reference, "Incompatible operand");