summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-27 14:09:08 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-27 14:09:08 +0000
commit5cfda37971da176ceba204d57acb5821c293d555 (patch)
tree6d19af6504aa9e50f72eff9523fe8523dad10e70 /compile.c
parent1474acff3c70c3c81cb1b059a8e6cc77a0fc4b70 (diff)
downloadruby-5cfda37971da176ceba204d57acb5821c293d555.tar.gz
fix return in toplevel ensure
* compile.c (iseq_compile_each0): adjust stack after return in toplevel ensure, when the value is used. [ruby-core:81777] [Bug #13682] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/compile.c b/compile.c
index f1957f4908..f0c7499723 100644
--- a/compile.c
+++ b/compile.c
@@ -4824,8 +4824,6 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popp
CHECK(COMPILE_POPPED(ensr, "ensure ensr", node->nd_ensr));
last = ensr->last;
last_leave = last && IS_INSN(last) && IS_INSN_ID(last, leave);
- if (!popped && last_leave)
- popped = 1;
er.begin = lstart;
er.end = lend;
@@ -4833,13 +4831,16 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popp
push_ensure_entry(iseq, &enl, &er, node->nd_ensr);
ADD_LABEL(ret, lstart);
- CHECK(COMPILE_(ret, "ensure head", node->nd_head, popped));
+ CHECK(COMPILE_(ret, "ensure head", node->nd_head, (popped | last_leave)));
ADD_LABEL(ret, lend);
if (ensr->anchor.next == NULL) {
ADD_INSN(ret, line, nop);
}
else {
ADD_SEQ(ret, ensr);
+ if (!popped && last_leave) {
+ ADD_INSN(ret, line, putnil);
+ }
}
ADD_LABEL(ret, lcont);
if (last_leave) ADD_INSN(ret, line, pop);