summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-27 06:57:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-27 06:57:34 +0000
commit1474acff3c70c3c81cb1b059a8e6cc77a0fc4b70 (patch)
tree7c657a90b1ea8f6f7fd830a695d9332cedce2d98 /compile.c
parentc95cbf6aab15de1c14eb924832e6ae7be2d74754 (diff)
fix return in toplevel rescue/ensure
* compile.c (iseq_compile_each0): throw TAG_RETURN at return in toplevel rescue/ensure to adjust VM stack properly. [ruby-core:81777] [Bug #13682] * vm_insnhelper.c (vm_throw_start): allow return in toplevel rescue/ensure. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/compile.c b/compile.c
index 6e37dbf9ba..f1957f4908 100644
--- a/compile.c
+++ b/compile.c
@@ -5657,15 +5657,23 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popp
if (is) {
enum iseq_type type = is->body->type;
const rb_iseq_t *parent_iseq = is->body->parent_iseq;
- enum iseq_type parent_type = parent_iseq ? parent_iseq->body->type : type;
+ enum iseq_type parent_type;
- if (type == ISEQ_TYPE_TOP || type == ISEQ_TYPE_MAIN ||
- ((type == ISEQ_TYPE_RESCUE || type == ISEQ_TYPE_ENSURE) &&
- (parent_type == ISEQ_TYPE_TOP || parent_type == ISEQ_TYPE_MAIN))) {
+ if (type == ISEQ_TYPE_TOP || type == ISEQ_TYPE_MAIN) {
ADD_ADJUST(ret, line, 0);
ADD_INSN(ret, line, putnil);
ADD_INSN(ret, line, leave);
}
+ else if ((type == ISEQ_TYPE_RESCUE || type == ISEQ_TYPE_ENSURE) &&
+ parent_iseq &&
+ ((parent_type = parent_iseq->body->type) == ISEQ_TYPE_TOP ||
+ parent_type == ISEQ_TYPE_MAIN)) {
+ ADD_INSN(ret, line, putnil);
+ ADD_INSN1(ret, line, throw, INT2FIX(TAG_RETURN));
+ if (popped) {
+ ADD_INSN(ret, line, pop);
+ }
+ }
else {
LABEL *splabel = 0;