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]
上级 c53aebb1
......@@ -59,6 +59,7 @@ def test_defined_protected_method
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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册