]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Support postfix operator on array members
authorJürg Billeter <j@bitron.ch>
Tue, 29 Sep 2009 20:19:18 +0000 (22:19 +0200)
committerJürg Billeter <j@bitron.ch>
Tue, 29 Sep 2009 20:19:18 +0000 (22:19 +0200)
Fixes bug 596637.

tests/Makefile.am
tests/basic-types/bug596637.vala [new file with mode: 0644]
vala/valapostfixexpression.vala

index f1058b826ea93bb5409987a887a85d3bd0f42fe6..821b4a259810393c7769191078a41988672bc5c3 100644 (file)
@@ -20,6 +20,7 @@ TESTS = \
        basic-types/strings.vala \
        basic-types/arrays.vala \
        basic-types/pointers.vala \
+       basic-types/bug596637.vala \
        namespaces.vala \
        methods/lambda.vala \
        methods/closures.vala \
diff --git a/tests/basic-types/bug596637.vala b/tests/basic-types/bug596637.vala
new file mode 100644 (file)
index 0000000..904de17
--- /dev/null
@@ -0,0 +1,5 @@
+void main () {
+       int[] a = new int[1];
+       a[0]++;
+       assert (a[0] == 1);
+}
index 1ed72e16301bf78b9e51cff18e54a7f6f9fa3c78..b9d6af13f1680050d524274c2eee51846aa47c42 100644 (file)
@@ -74,7 +74,7 @@ public class Vala.PostfixExpression : Expression {
                        return false;
                }
 
-               if (inner.value_type == null) {
+               if (!(inner.value_type is IntegerType) && !(inner.value_type is FloatingType) && !(inner.value_type is PointerType)) {
                        error = true;
                        Report.error (source_reference, "unsupported lvalue in postfix expression");
                        return false;
@@ -94,6 +94,13 @@ public class Vala.PostfixExpression : Expression {
                                /* if no symbol found, skip this check */
                                return false;
                        }
+               } else if (inner is ElementAccess) {
+                       var ea = (ElementAccess) inner;
+                       if (!(ea.container.value_type is ArrayType)) {
+                               error = true;
+                               Report.error (source_reference, "unsupported lvalue in postfix expression");
+                               return false;
+                       }
                } else {
                        error = true;
                        Report.error (source_reference, "unsupported lvalue in postfix expression");