[vala/0.40] codegen: Use result value of assignment rather than its computation
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] codegen: Use result value of assignment rather than its computation
- Date: Wed, 5 Feb 2020 10:03:16 +0000 (UTC)
commit 8edce88b72a766242273e62e3963f45777d767ec
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Jan 14 08:36:26 2020 +0100
codegen: Use result value of assignment rather than its computation
An inline assignment of an array-length, like
int j = --i.length;
resulted in a faulty tranformation
i_length1 = i_length1 - 1;
j = i_length1 - 1;
Regression of 80d4bf61e0c3100c839f3fdbcb5218996b6afd5f
Fixes https://gitlab.gnome.org/GNOME/vala/issues/895
codegen/valaccodeassignmentmodule.vala | 2 +-
tests/Makefile.am | 1 +
tests/arrays/length-inline-assignment.vala | 29 +++++++++++++++++++++++++++++
3 files changed, 31 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index 1b68b3764..07faaa13a 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -71,7 +71,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
if (assignment.left.value_type is ArrayType && (((ArrayType)
assignment.left.value_type).inline_allocated)) {
return load_variable (variable, assignment.left.target_value);
} else {
- return assignment.right.target_value;
+ return assignment.left.target_value;
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2fb048652..a5471f9fc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -69,6 +69,7 @@ TESTS = \
arrays/fixed-length-concat-invalid.test \
arrays/fixed-length-non-const.test \
arrays/fixed-length-resize-invalid.test \
+ arrays/length-inline-assignment.vala \
arrays/struct-field-length-cname.vala \
arrays/slice-invalid-start.test \
arrays/slice-invalid-stop.test \
diff --git a/tests/arrays/length-inline-assignment.vala b/tests/arrays/length-inline-assignment.vala
new file mode 100644
index 000000000..baf33055d
--- /dev/null
+++ b/tests/arrays/length-inline-assignment.vala
@@ -0,0 +1,29 @@
+void main () {
+ {
+ int[] i = { 23, 42 };
+ int j = --i.length;
+ assert (i.length == 1);
+ assert (j == 1);
+ j = ++i.length;
+ assert (i.length == 2);
+ assert (j == 2);
+ }
+ {
+ int[] i = { 23, 42 };
+ int j = (i.length = i.length - 1);
+ assert (i.length == 1);
+ assert (j == 1);
+ j = (i.length = i.length + 1);
+ assert (i.length == 2);
+ assert (j == 2);
+ }
+ {
+ int[] i = { 23, 42 };
+ int j = i.length--;
+ assert (i.length == 1);
+ assert (j == 2);
+ j = i.length++;
+ assert (i.length == 2);
+ assert (j == 1);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]