mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fixed defined?
against protected method call
Protected methods are restricted to be called according to the class/module in where it is defined, not the actual receiver's class. [Bug #16931]
This commit is contained in:
parent
c53aebb1d2
commit
d05f04d27d
2 changed files with 2 additions and 1 deletions
|
@ -59,6 +59,7 @@ class TestDefined < Test::Unit::TestCase
|
|||
f = Foo.new
|
||||
assert_nil(defined?(f.foo)) # protected method
|
||||
f.bar(f) { |v| assert(v) }
|
||||
f.bar(Class.new(Foo).new) { |v| assert(v, "inherited protected method") }
|
||||
end
|
||||
|
||||
def test_defined_undefined_method
|
||||
|
|
|
@ -3603,7 +3603,7 @@ vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_
|
|||
case METHOD_VISI_PRIVATE:
|
||||
break;
|
||||
case METHOD_VISI_PROTECTED:
|
||||
if (!rb_obj_is_kind_of(GET_SELF(), rb_class_real(klass))) {
|
||||
if (!rb_obj_is_kind_of(GET_SELF(), rb_class_real(me->defined_class))) {
|
||||
break;
|
||||
}
|
||||
case METHOD_VISI_PUBLIC:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue