Skip to content

Commit

Permalink
vala: Do not allow to change .length of arrays with fixed length
Browse files Browse the repository at this point in the history
This would result in invalid C code.
  • Loading branch information
flobrosch authored and ricotz committed Oct 30, 2019
1 parent 030093b commit efb5479
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/arrays/fixed-length-read-only-length.test
@@ -0,0 +1,6 @@
Invalid Code

void main () {
int foo[2] = { 23, 42 };
foo.length = 3;
}
4 changes: 4 additions & 0 deletions vala/valaassignment.vala
Expand Up @@ -290,6 +290,10 @@ public class Vala.Assignment : Expression {
return false;
}
}
} else if (ma.symbol_reference is ArrayLengthField && ((ArrayType) ma.inner.value_type).inline_allocated) {
error = true;
Report.error (source_reference, "`length' field of fixed length arrays is read-only");
return false;
} else if (ma.symbol_reference is Variable && right.value_type == null) {
var variable = (Variable) ma.symbol_reference;

Expand Down

0 comments on commit efb5479

Please sign in to comment.