summaryrefslogtreecommitdiffhomepage
path: root/src/kernel.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-12-11 00:36:18 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-12-11 00:36:18 +0900
commit44c29e88aeaf241915b3d10a44d4a3748d1a6328 (patch)
treef2082f7d3a70c525c82da7ea739522cb44c6bbf3 /src/kernel.c
parent4eff93632f6d96aa8dd6aaf0513c22c3c3abfda3 (diff)
downloadmruby-44c29e88aeaf241915b3d10a44d4a3748d1a6328.tar.gz
mruby-44c29e88aeaf241915b3d10a44d4a3748d1a6328.zip
block_given did not work with nested block invocation for some cases; fix #2665
Diffstat (limited to 'src/kernel.c')
-rw-r--r--src/kernel.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/kernel.c b/src/kernel.c
index 22fe40218..cb938f152 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -187,15 +187,19 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
else {
/* block_given? called within block; check upper scope */
if (ci->proc->env && ci->proc->env->stack) {
- given_p = !(ci->proc->env->stack == mrb->c->stbase ||
- mrb_nil_p(ci->proc->env->stack[1]));
- }
- else {
- if (ci->argc > 0) {
- bp += ci->argc;
+ mrb_value *sp = ci->proc->env->stack;
+
+ while (mrb->c->cibase < ci) {
+ if (ci->stackent == sp) {
+ break;
+ }
+ ci--;
}
- given_p = !mrb_nil_p(*bp);
}
+ if (ci->argc > 0) {
+ bp += ci->argc;
+ }
+ given_p = !mrb_nil_p(*bp);
}
return mrb_bool_value(given_p);