From 5e6ea6c5f968a2aaadfb883b90cadee35410ae23 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 1 Mar 2025 19:24:55 +0900 Subject: [PATCH] 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. --- src/vm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vm.c b/src/vm.c index 20d9b4f85..09ae7c651 100644 --- a/src/vm.c +++ b/src/vm.c @@ -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;