From 7d3290e44c1acba6b18584f4c52d40765883b581 Mon Sep 17 00:00:00 2001 From: Florian Brosch Date: Wed, 17 Sep 2014 00:17:01 +0200 Subject: [PATCH] vala: Do not allow += for arrays with fixed length --- tests/Makefile.am | 1 + tests/arrays/fixed-length-concat-invalid.test | 6 ++++++ vala/valabinaryexpression.vala | 4 ++++ 3 files changed, 11 insertions(+) create mode 100644 tests/arrays/fixed-length-concat-invalid.test diff --git a/tests/Makefile.am b/tests/Makefile.am index a80d7a27a..775110cbb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 \ diff --git a/tests/arrays/fixed-length-concat-invalid.test b/tests/arrays/fixed-length-concat-invalid.test new file mode 100644 index 000000000..99f24a34b --- /dev/null +++ b/tests/arrays/fixed-length-concat-invalid.test @@ -0,0 +1,6 @@ +Invalid Code + +void main () { + int foo[2] = { 23, 42 }; + foo += 4711; +} diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala index f9b66e377..4f1f642f5 100644 --- a/vala/valabinaryexpression.vala +++ b/vala/valabinaryexpression.vala @@ -346,6 +346,10 @@ public class Vala.BinaryExpression : Expression { unowned ArrayType 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"); -- 2.47.2