1
0
Fork 0
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:
Nobuyoshi Nakada 2020-06-02 18:55:06 +09:00
parent c53aebb1d2
commit d05f04d27d
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 2 additions and 1 deletions

View file

@ -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

View file

@ -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: