summaryrefslogtreecommitdiffhomepage
path: root/src/vm.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-11-04 11:20:04 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-11-04 11:20:04 +0900
commit388d26d77027feaa3e107abf7209e2681868bbe6 (patch)
tree938403632a0ebd14790c5f27df3dcdc19c6caee7 /src/vm.c
parentab27abe0834bc9da38d4a4d895514a66ea53fe84 (diff)
downloadmruby-388d26d77027feaa3e107abf7209e2681868bbe6.tar.gz
mruby-388d26d77027feaa3e107abf7209e2681868bbe6.zip
Reimplement `block_given?`; ref #3841
Make `block_given?` to search for the top of the scope first. The top of the scope means either: * the top method body * the enclosing class body * the top-level The special case is the method defined by `define_method` with a block as in #3841. In cases like this, the method body (given by a block) is not considered as the top of the scope. You need to use `&block` in the block parameter if you want to know if a block is given to the method. This commit also changes the behavior of `MRB_PROC_SCOPE` flag. Now it is only set if the `proc` is either a class body or a method body defined in Ruby. It is no longer set for a block that given to `define_method`.
Diffstat (limited to 'src/vm.c')
-rw-r--r--src/vm.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/vm.c b/src/vm.c
index e5b7de0da..37b7b3c4d 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -2651,6 +2651,7 @@ RETRY_TRY_BLOCK:
}
else {
p = mrb_proc_new(mrb, nirep);
+ p->flags |= MRB_PROC_SCOPE;
}
if (c & OP_L_STRICT) p->flags |= MRB_PROC_STRICT;
regs[a] = mrb_obj_value(p);