diff options
-rw-r--r-- | test/ruby/test_refinement.rb | 44 | ||||
-rw-r--r-- | vm_insnhelper.c | 5 |
2 files changed, 47 insertions, 2 deletions
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 82bdb49659..c7df789306 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -1900,6 +1900,50 @@ class TestRefinement < Test::Unit::TestCase end end + class ParentDefiningPrivateMethod + private + def some_inherited_method + end + end + + module MixinDefiningPrivateMethod + private + def some_included_method + end + end + + class SomeChildClassToRefine < ParentDefiningPrivateMethod + include MixinDefiningPrivateMethod + + private + def some_method + end + end + + def test_refine_inherited_method_with_visibility_changes + Module.new do + refine(SomeChildClassToRefine) do + def some_inherited_method; end + def some_included_method; end + def some_method; end + end + end + + obj = SomeChildClassToRefine.new + + assert_raise_with_message(NoMethodError, /private/) do + obj.some_inherited_method + end + + assert_raise_with_message(NoMethodError, /private/) do + obj.some_included_method + end + + assert_raise_with_message(NoMethodError, /private/) do + obj.some_method + end + end + private def eval_using(mod, s) diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 856178d5d0..d835997f7c 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2283,11 +2283,12 @@ vm_call_method_each_type(rb_thread_t *th, rb_control_frame_t *cfp, struct rb_cal no_refinement_dispatch: if (cc->me->def->body.refined.orig_me) { cc->me = refined_method_callable_without_refinement(cc->me); - return vm_call_method(th, cfp, calling, ci, cc); } else { - return vm_call_zsuper(th, cfp, calling, ci, cc, cc->me->owner); + VALUE klass = RCLASS_SUPER(cc->me->owner); + cc->me = klass ? rb_callable_method_entry(klass, ci->mid) : NULL; } + return vm_call_method(th, cfp, calling, ci, cc); } } |