ruby-changes:66363
From: nagachika <ko1@a...>
Date: Sat, 29 May 2021 14:56:43 +0900 (JST)
Subject: [ruby-changes:66363] a21ec8d1ec (ruby_3_0): merge revision(s) 636d4f7eb9f3fcb088e1a44af4181c4aa36789b4: [Backport #17822]
https://git.ruby-lang.org/ruby.git/commit/?id=a21ec8d1ec From a21ec8d1ecc6e978ea6b18a27046c424e2849752 Mon Sep 17 00:00:00 2001 From: nagachika <nagachika@r...> Date: Sat, 29 May 2021 14:36:28 +0900 Subject: merge revision(s) 636d4f7eb9f3fcb088e1a44af4181c4aa36789b4: [Backport #17822] Avoid setting the visibility of refinement method entries Since refinement search is always performed, these entries should always be public. The method entry that the refinement search returns decides the visibility. Fixes [Bug #17822] --- test/ruby/test_refinement.rb | 22 ++++++++++++++++++++++ vm_method.c | 15 ++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) --- test/ruby/test_refinement.rb | 22 ++++++++++++++++++++++ version.h | 2 +- vm_method.c | 15 ++++++++++----- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index b386c3a..ed31fae 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -2537,6 +2537,28 @@ class TestRefinement < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L2537 assert_equal(:second, klass.new.foo) end + class Bug17822 + module Ext + refine(Bug17822) do + def foo = :refined + end + end + + private(def foo = :not_refined) + + module Client + using Ext + def self.call_foo + Bug17822.new.foo + end + end + end + + # [Bug #17822] + def test_privatizing_refined_method + assert_equal(:refined, Bug17822::Client.call_foo) + end + private def eval_using(mod, s) diff --git a/version.h b/version.h index a9ea2b3..f47855f 100644 --- a/version.h +++ b/version.h @@ -12,7 +12,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L12 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 2 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 92 +#define RUBY_PATCHLEVEL 93 #define RUBY_RELEASE_YEAR 2021 #define RUBY_RELEASE_MONTH 5 diff --git a/vm_method.c b/vm_method.c index a467ac1..e55fc46 100644 --- a/vm_method.c +++ b/vm_method.c @@ -1401,11 +1401,16 @@ rb_export_method(VALUE klass, ID name, rb_method_visibility_t visi) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1401 rb_vm_check_redefinition_opt_method(me, klass); if (klass == defined_class || origin_class == defined_class) { - METHOD_ENTRY_VISI_SET(me, visi); - - if (me->def->type == VM_METHOD_TYPE_REFINED && me->def->body.refined.orig_me) { - METHOD_ENTRY_VISI_SET((rb_method_entry_t *)me->def->body.refined.orig_me, visi); - } + if (me->def->type == VM_METHOD_TYPE_REFINED) { + // Refinement method entries should always be public because the refinement + // search is always performed. + if (me->def->body.refined.orig_me) { + METHOD_ENTRY_VISI_SET((rb_method_entry_t *)me->def->body.refined.orig_me, visi); + } + } + else { + METHOD_ENTRY_VISI_SET(me, visi); + } rb_clear_method_cache(klass, name); } else { -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/