Skip to content

Commit

Permalink
vala: Do not allow to .resize() on 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 67d8e3f commit 030093b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/Makefile.am
Expand Up @@ -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 \
Expand Down
6 changes: 6 additions & 0 deletions tests/arrays/fixed-length-resize-invalid.test
@@ -0,0 +1,6 @@
Invalid Code

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

0 comments on commit 030093b

Please sign in to comment.