mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
visibility of inherited method
* vm_insnhelper.c (vm_call_method_each_type): honor the original visibility of inherited methods when a refinement is defined but not activated. [ruby-core:82209] [Bug #13776] Author: Mon_Ouie (Mon ouïe) <mon.ouie@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
97c977debf
commit
3449d4fa2d
2 changed files with 47 additions and 2 deletions
|
@ -1900,6 +1900,50 @@ class TestRefinement < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def eval_using(mod, s)
|
def eval_using(mod, s)
|
||||||
|
|
|
@ -2283,11 +2283,12 @@ vm_call_method_each_type(rb_thread_t *th, rb_control_frame_t *cfp, struct rb_cal
|
||||||
no_refinement_dispatch:
|
no_refinement_dispatch:
|
||||||
if (cc->me->def->body.refined.orig_me) {
|
if (cc->me->def->body.refined.orig_me) {
|
||||||
cc->me = refined_method_callable_without_refinement(cc->me);
|
cc->me = refined_method_callable_without_refinement(cc->me);
|
||||||
return vm_call_method(th, cfp, calling, ci, cc);
|
|
||||||
}
|
}
|
||||||
else {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue