Fixed also argument forwarding in class_exec

Pointed out by @matz.
https://github.com/mruby/mruby/pull/6391#issuecomment-2433662139
This commit is contained in:
dearblue
2024-10-24 22:05:59 +09:00
parent f9151e0bd9
commit a196d8a5f3
2 changed files with 19 additions and 12 deletions
+2 -12
View File
@@ -4,6 +4,7 @@
#include <mruby/array.h>
#include <mruby/proc.h>
#include <mruby/variable.h>
#include <mruby/internal.h>
#include <mruby/presym.h>
static mrb_value
@@ -44,18 +45,7 @@ mod_singleton_class_p(mrb_state *mrb, mrb_value self)
static mrb_value
mod_module_exec(mrb_state *mrb, mrb_value self)
{
const mrb_value *argv;
mrb_int argc;
mrb_value blk;
mrb_get_args(mrb, "*&!", &argv, &argc, &blk);
struct RClass *c = mrb_class_ptr(self);
if (mrb->c->ci->cci > 0) {
return mrb_yield_with_class(mrb, blk, argc, argv, self, c);
}
mrb_vm_ci_target_class_set(mrb->c->ci, c);
return mrb_yield_cont(mrb, blk, self, argc, argv);
return mrb_object_exec(mrb, self, mrb_class_ptr(self));
}
struct subclass_args {
+17
View File
@@ -27,3 +27,20 @@ assert 'Class#attached_object' do
assert_raise(TypeError){TrueClass.attached_object}
assert_raise(TypeError){NilClass.attached_object}
end
assert 'Class#class_exec' do
c = Class.new
class << c
def index
12345
end
end
c.class_exec do
def index
54321
end
end
assert_equal 12345, c.index
assert_equal 54321, c.new.index
end