merge revision(s) 58918788ab: [Backport #20342]

[Bug #20342] Consider wrapped load in `main` methods
This commit is contained in:
nagachika 2024-07-15 17:56:01 +09:00
parent bfdb6d5a9d
commit b72deb7ca1
6 changed files with 37 additions and 22 deletions

18
eval.c
View file

@ -1777,6 +1777,16 @@ rb_obj_extend(int argc, VALUE *argv, VALUE obj)
return obj;
}
VALUE
rb_top_main_class(const char *method)
{
VALUE klass = GET_THREAD()->top_wrapper;
if (!klass) return rb_cObject;
rb_warning("main.%s in the wrapped load is effective only in wrapper module", method);
return klass;
}
/*
* call-seq:
* include(module, ...) -> self
@ -1789,13 +1799,7 @@ rb_obj_extend(int argc, VALUE *argv, VALUE obj)
static VALUE
top_include(int argc, VALUE *argv, VALUE self)
{
rb_thread_t *th = GET_THREAD();
if (th->top_wrapper) {
rb_warning("main.include in the wrapped load is effective only in wrapper module");
return rb_mod_include(argc, argv, th->top_wrapper);
}
return rb_mod_include(argc, argv, rb_cObject);
return rb_mod_include(argc, argv, rb_top_main_class("include"));
}
/*