mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Support using at toplevel in wrapped script
Allow refinements to be used at the toplevel within a script that is loaded under a module. Fixes [Bug #18960]
This commit is contained in:
parent
a74f4cded2
commit
82ac4a2399
Notes:
git
2022-09-24 09:41:38 +09:00
5 changed files with 35 additions and 2 deletions
6
eval.c
6
eval.c
|
@ -1792,10 +1792,12 @@ top_include(int argc, VALUE *argv, VALUE self)
|
|||
static VALUE
|
||||
top_using(VALUE self, VALUE module)
|
||||
{
|
||||
const rb_cref_t *cref = rb_vm_cref();
|
||||
const rb_cref_t *cref = CREF_NEXT(rb_vm_cref());;
|
||||
rb_control_frame_t *prev_cfp = previous_frame(GET_EC());
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
|
||||
if (CREF_NEXT(cref) || (prev_cfp && rb_vm_frame_method_entry(prev_cfp))) {
|
||||
if ((th->top_wrapper ? CREF_NEXT(cref) : cref) ||
|
||||
(prev_cfp && rb_vm_frame_method_entry(prev_cfp))) {
|
||||
rb_raise(rb_eRuntimeError, "main.using is permitted only at toplevel");
|
||||
}
|
||||
if (rb_block_given_p()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue