Skip to content

Fix calling symbol proc from using scope outside #13230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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]
  • Loading branch information
XrXr committed May 1, 2025
commit c8f2ecbe282d58aedba3602d6179ca8ee0ed3967
12 changes: 12 additions & 0 deletions test/ruby/test_refinement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2712,6 +2712,18 @@ def test
INPUT
end

# [Bug #21265]
def test_symbol_proc_from_using_scope
assert_separately([], <<~RUBY)
class RefinedScope
using(Module.new { refine(Kernel) { def itself = 0 } })
ITSELF = :itself.to_proc
end

assert_equal(1, RefinedScope::ITSELF[1])
RUBY
end

private

def eval_using(mod, s)
Expand Down
1 change: 0 additions & 1 deletion vm_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,6 @@ resolve_refined_method(VALUE refinements, const rb_method_entry_t *me, VALUE *de

tmp_me = me->def->body.refined.orig_me;
if (tmp_me) {
if (defined_class_ptr) *defined_class_ptr = tmp_me->defined_class;
return tmp_me;
}

Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy