Skip to content

Commit c8f2ecb

Browse files
committed
Fix calling symbol proc from using scope outside
Previously, resolve_refined_method() wrote to defined_class_ptr by using rb_method_entry_t::defined_class, which by definition can be 0. Since `*defined_class_ptr` is used as a back-up when rb_method_entry_t::defined_class is 0, this wasn't a good strategy to not have 0 at the end. This caused a crash since it overwrote a properly set defined_class put by a `search_method*` function earlier. Since resolve_refined_method() is always called after calling a `search_method_*` function which writes through defined_class_ptr already, just don't write through deinfed_class_ptr. [Bug #21265]
1 parent 5cee332 commit c8f2ecb

2 files changed

Lines changed: 12 additions & 1 deletion

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+
# [Bug #21265]
2716+
def test_symbol_proc_from_using_scope
2717+
assert_separately([], <<~RUBY)
2718+
class RefinedScope
2719+
using(Module.new { refine(Kernel) { def itself = 0 } })
2720+
ITSELF = :itself.to_proc
2721+
end
2722+
2723+
assert_equal(1, RefinedScope::ITSELF[1])
2724+
RUBY
2725+
end
2726+
27152727
private
27162728

27172729
def eval_using(mod, s)

vm_method.c

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

16371637
tmp_me = me->def->body.refined.orig_me;
16381638
if (tmp_me) {
1639-
if (defined_class_ptr) *defined_class_ptr = tmp_me->defined_class;
16401639
return tmp_me;
16411640
}
16421641

0 commit comments

Comments
 (0)