vm.c: restore visibility when reopen class/module definition

Ideally, the default visibility should be stored in the scope. But for
the time being mruby stores the visibility in the class/module. As a
result, nesting class/module reopening or class_eval/module_eval could
cause incompatibility. We will try to fix them in the future.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-03-01 19:24:55 +09:00
parent 2a876d2047
commit 5e6ea6c5f9
+4
View File
@@ -1011,6 +1011,7 @@ mrb_mod_module_eval(mrb_state *mrb, mrb_value mod)
if (mrb_get_args(mrb, "|S&", &a, &b) == 1) {
mrb_raise(mrb, E_NOTIMP_ERROR, "module_eval/class_eval with string not implemented");
}
MRB_SET_VISIBILITY(mrb_class_ptr(mod), MRB_METHOD_PUBLIC_FL);
return eval_under(mrb, mod, b, mrb_class_ptr(mod));
}
@@ -2940,6 +2941,9 @@ RETRY_TRY_BLOCK:
struct RClass *c = mrb_class_ptr(recv);
const mrb_irep *nirep = irep->reps[b];
/* restore visibility */
MRB_SET_VISIBILITY(c, MRB_METHOD_PUBLIC_FL);
/* prepare closure */
struct RProc *p = mrb_proc_new(mrb, nirep);
p->c = NULL;