[vala] Fix side-effects in array element assignments
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Fix side-effects in array element assignments
- Date: Sun, 17 Oct 2010 12:01:59 +0000 (UTC)
commit 6cec999ad890f9cfae84721014b8b0ea3bd5ac7e
Author: Jürg Billeter <j bitron ch>
Date: Sun Oct 17 13:59:31 2010 +0200
Fix side-effects in array element assignments
Make sure to not evaluate the index multiple times.
Fixes bug 632322.
tests/Makefile.am | 1 +
tests/basic-types/bug632322.vala | 6 ++++++
vala/valaassignment.vala | 16 ++++++++++------
3 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 08bf293..66b8c8f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,6 +23,7 @@ TESTS = \
basic-types/bug595751.vala \
basic-types/bug596637.vala \
basic-types/bug596785.vala \
+ basic-types/bug632322.vala \
namespaces.vala \
methods/lambda.vala \
methods/closures.vala \
diff --git a/tests/basic-types/bug632322.vala b/tests/basic-types/bug632322.vala
new file mode 100644
index 0000000..6116b96
--- /dev/null
+++ b/tests/basic-types/bug632322.vala
@@ -0,0 +1,6 @@
+void main () {
+ int[] foo = new int[42];
+ int i = 1;
+ foo[i = i - 1] = 23;
+ assert (i == 0);
+}
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index e136884..fbed65c 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -464,13 +464,17 @@ public class Vala.Assignment : Expression {
ma.inner.emit (codegen);
}
} else if (ea != null) {
- ea.container.emit (codegen);
-
- foreach (var index in ea.get_indices ()) {
- index.emit (codegen);
- }
+ // always process full lvalue
+ // current codegen depends on it
+ // should be removed when moving codegen from
+ // visit_assignment to emit_store_element
+ ea.emit (codegen);
} else if (pi != null) {
- pi.inner.emit (codegen);
+ // always process full lvalue
+ // current codegen depends on it
+ // should be removed when moving codegen from
+ // visit_assignment to emit_store_indirectZ
+ pi.emit (codegen);
}
right.emit (codegen);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]