Skip to content

Commit

Permalink
vala: Do not allow += for arrays with fixed length
Browse files Browse the repository at this point in the history
  • Loading branch information
flobrosch authored and ricotz committed Oct 30, 2019
1 parent f7b6119 commit eb9672b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/Makefile.am
Expand Up @@ -74,6 +74,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 \
Expand Down
6 changes: 6 additions & 0 deletions tests/arrays/fixed-length-concat-invalid.test
@@ -0,0 +1,6 @@
Invalid Code

void main () {
int foo[2] = { 23, 42 };
foo += 4711;
}
4 changes: 4 additions & 0 deletions vala/valabinaryexpression.vala
Expand Up @@ -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");
Expand Down

0 comments on commit eb9672b

Please sign in to comment.