ref: 5d433bdf4af606e395b54aace8c0a27f745ae9ce
parent: a2352649c2a8f5937335a8c791f3581f52cd8d6f
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Oct 8 20:26:30 EDT 2016
Fix bug with postinc returns. We were draining the postinc queue before the rval. Oops.
--- a/mi/flatten.c
+++ b/mi/flatten.c
@@ -468,10 +468,17 @@
break;;
case Oret:
/* drain the increment queue before we return */
- t = rval(s, args[0]);
- for (i = 0; i < s->nqueue; i++)
- append(s, s->incqueue[i]);
- lfree(&s->incqueue, &s->nqueue);
+ v = rval(s, args[0]);
+ if (!s->nqueue) {
+ t = v;
+ } else {
+ t = temp(s, v);
+ u = assign(s, t, v);
+ append(s, u);
+ for (i = 0; i < s->nqueue; i++)
+ append(s, s->incqueue[i]);
+ lfree(&s->incqueue, &s->nqueue);
+ }
append(s, mkexpr(n->loc, Oret, t, NULL));
break;
case Oasn:
--- /dev/null
+++ b/test/postinc-ret.myr
@@ -1,0 +1,12 @@
+use std
+
+const main = {
+ std.put("{}\n", f())
+}
+
+const a = [1,2,3][:]
+const f = {
+ var i = 0
+ -> a[i++]
+}
+
--- a/test/tests
+++ b/test/tests
@@ -33,6 +33,7 @@
B swidencast E 99
B derefassign E 123
B ptrpreinc E 9
+B postinc-ret P '1'
B incret E 1
B outparam E 42
B outparam-sl E 2