summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2023-03-08 20:16:51 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2023-03-08 20:22:38 +0100
commit2485098aa1a16018b2b748a723177e71e093ab73 (patch)
tree038903bbc1c3841b0937fc13ecc847d15d296bab
parent7da7cb4f369876dcf807d78961a65db67db9e228 (diff)
downloadvala-2485098aa1a16018b2b748a723177e71e093ab73.tar.gz
vala: Correctly handle pre/post-increment expression as index of element access
Regression of cb1828cfc5273aca752de9b39a77e0cd53305e61 Fixes https://gitlab.gnome.org/GNOME/vala/issues/1417
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/basic-types/bug596637.c-expected14
-rw-r--r--tests/control-flow/pre-post-increment-array-index.c-expected45
-rw-r--r--tests/control-flow/pre-post-increment-array-index.vala14
-rw-r--r--vala/valamemberaccess.vala2
5 files changed, 66 insertions, 10 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9257e61ae..499d7f0d4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -311,6 +311,7 @@ TESTS = \
control-flow/nested-conditional.vala \
control-flow/null-conditional-bool.vala \
control-flow/pre-post-increment.vala \
+ control-flow/pre-post-increment-array-index.vala \
control-flow/pre-post-increment-field.vala \
control-flow/pre-post-increment-local.vala \
control-flow/pre-post-increment-parameter.vala \
diff --git a/tests/basic-types/bug596637.c-expected b/tests/basic-types/bug596637.c-expected
index 5d29263b7..2bdb6d02c 100644
--- a/tests/basic-types/bug596637.c-expected
+++ b/tests/basic-types/bug596637.c-expected
@@ -17,20 +17,16 @@ _vala_main (void)
gint* _tmp0_;
gint a_length1;
gint _a_size_;
- gint* _tmp1_;
- gint _tmp1__length1;
+ gint _tmp1_;
gint _tmp2_;
- gint _tmp3_;
_tmp0_ = g_new0 (gint, 1);
a = _tmp0_;
a_length1 = 1;
_a_size_ = a_length1;
- _tmp1_ = a;
- _tmp1__length1 = a_length1;
- _tmp2_ = _tmp1_[0];
- _tmp1_[0] = _tmp2_ + 1;
- _tmp3_ = a[0];
- _vala_assert (_tmp3_ == 1, "a[0] == 1");
+ _tmp1_ = a[0];
+ a[0] = _tmp1_ + 1;
+ _tmp2_ = a[0];
+ _vala_assert (_tmp2_ == 1, "a[0] == 1");
a = (g_free (a), NULL);
}
diff --git a/tests/control-flow/pre-post-increment-array-index.c-expected b/tests/control-flow/pre-post-increment-array-index.c-expected
new file mode 100644
index 000000000..da5169eee
--- /dev/null
+++ b/tests/control-flow/pre-post-increment-array-index.c-expected
@@ -0,0 +1,45 @@
+/* control_flow_pre_post_increment_array_index.c generated by valac, the Vala compiler
+ * generated from control_flow_pre_post_increment_array_index.vala, do not modify */
+
+#include <glib.h>
+
+#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
+#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
+#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
+#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
+
+static void _vala_main (void);
+
+static void
+_vala_main (void)
+{
+ gchar foo[4] = {0};
+ gint i = 0;
+ gint _tmp0_;
+ gint _tmp1_;
+ gint _tmp2_;
+ foo[4] = '\0';
+ i = 0;
+ _tmp0_ = i;
+ i = _tmp0_ + 1;
+ foo[_tmp0_] = 'b';
+ i = 0;
+ i = i + 1;
+ _tmp1_ = i;
+ foo[_tmp1_] = 'a';
+ i = 2;
+ _tmp2_ = i;
+ i = _tmp2_ + 1;
+ foo[_tmp2_] = 'r';
+ _vala_assert (i == 3, "i == 3");
+ _vala_assert (g_strcmp0 ((const gchar*) foo, "bar") == 0, "(string) foo == \"bar\"");
+}
+
+int
+main (int argc,
+ char ** argv)
+{
+ _vala_main ();
+ return 0;
+}
+
diff --git a/tests/control-flow/pre-post-increment-array-index.vala b/tests/control-flow/pre-post-increment-array-index.vala
new file mode 100644
index 000000000..c8a08feca
--- /dev/null
+++ b/tests/control-flow/pre-post-increment-array-index.vala
@@ -0,0 +1,14 @@
+void main () {
+ char foo[4];
+ foo[4] = '\0';
+
+ var i = 0;
+ foo[i++] = 'b';
+ i = 0;
+ foo[++i] = 'a';
+ i = 2;
+ foo[i++] = 'r';
+
+ assert (i == 3);
+ assert ((string) foo == "bar");
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 3b91ece73..2b75adcc5 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -1200,7 +1200,7 @@ public class Vala.MemberAccess : Expression {
bool is_tainted () {
unowned CodeNode node = this;
- if (node.parent_node is MemberAccess) {
+ if (node.parent_node is ElementAccess || node.parent_node is MemberAccess) {
return false;
}