Skip to content

Commit 625eeae

Browse files
committed
merge revision(s) a4dff09: [Backport #21265]
[PATCH] [Bug #21673] Fix resolving refined module-defined method A method defined in a module has no `defined_class`, use the ICLASS for it as the `defined_class`.
1 parent da66b64 commit 625eeae

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

test/ruby/test_refinement.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,6 +2712,18 @@ def test
27122712
INPUT
27132713
end
27142714

2715+
def test_refined_module_method
2716+
m = Module.new {
2717+
x = Module.new {def qux;end}
2718+
refine(x) {def qux;end}
2719+
break x
2720+
}
2721+
extend m
2722+
meth = method(:qux)
2723+
assert_equal m, meth.owner
2724+
assert_equal :qux, meth.name
2725+
end
2726+
27152727
def test_symbol_proc_from_using_scope
27162728
# assert_separately to contain the side effects of refining Kernel
27172729
assert_separately([], <<~RUBY)

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 7
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 65
14+
#define RUBY_PATCHLEVEL 66
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

vm_method.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,12 @@ resolve_refined_method(VALUE refinements, const rb_method_entry_t *me, VALUE *de
16381638

16391639
tmp_me = me->def->body.refined.orig_me;
16401640
if (tmp_me) {
1641-
if (defined_class_ptr) *defined_class_ptr = tmp_me->defined_class;
1641+
if (!tmp_me->defined_class) {
1642+
VM_ASSERT_TYPE(tmp_me->owner, T_MODULE);
1643+
}
1644+
else if (defined_class_ptr) {
1645+
*defined_class_ptr = tmp_me->defined_class;
1646+
}
16421647
return tmp_me;
16431648
}
16441649

0 commit comments

Comments
 (0)