summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-01 03:26:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-01 03:26:55 +0000
commitae49dbd392083f69026f2a0fff4a1d5f42d172a7 (patch)
tree020afa61632672395e5b081fcd0c33277755462e /compile.c
parentbdac4b6ee95d4a4e1458c5c3d41e631a81062ffd (diff)
compile.c: refactored compile_return
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/compile.c b/compile.c
index 77d6fc8672..c90db528e4 100644
--- a/compile.c
+++ b/compile.c
@@ -5109,20 +5109,26 @@ compile_return(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node,
if (iseq) {
enum iseq_type type = iseq->body->type;
- const rb_iseq_t *parent_iseq = iseq->body->parent_iseq;
- enum iseq_type parent_type;
+ const rb_iseq_t *is = iseq;
+ enum iseq_type t = type;
const NODE *retval = node->nd_stts;
LABEL *splabel = 0;
- if (type == ISEQ_TYPE_TOP) {
- retval = 0;
- type = ISEQ_TYPE_METHOD;
+ while (t == ISEQ_TYPE_RESCUE || t == ISEQ_TYPE_ENSURE) {
+ if (!(is = is->body->parent_iseq)) break;
+ t = is->body->type;
}
- else if ((type == ISEQ_TYPE_RESCUE || type == ISEQ_TYPE_ENSURE || type == ISEQ_TYPE_MAIN) &&
- parent_iseq &&
- ((parent_type = parent_iseq->body->type) == ISEQ_TYPE_TOP ||
- parent_type == ISEQ_TYPE_MAIN)) {
+ switch (t) {
+ case ISEQ_TYPE_TOP:
+ case ISEQ_TYPE_MAIN:
+ if (is == iseq) {
+ /* plain top-level, leave directly */
+ type = ISEQ_TYPE_METHOD;
+ }
retval = 0;
+ break;
+ default:
+ break;
}
if (type == ISEQ_TYPE_METHOD) {