* vm_insnhelper.c (vm_defined): skip respond_to_missing? when

a method is available.
  [Bug #11211]
* test/ruby/test_defined.rb: add a test for this fix.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50737 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2015-06-02 19:36:43 +00:00
Родитель 15164bf33c
Коммит 5bcae57c6f
3 изменённых файлов: 37 добавлений и 7 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Wed Jun 3 04:34:39 2015 Koichi Sasada <ko1@atdot.net>
* vm_insnhelper.c (vm_defined): skip respond_to_missing? when
a method is available.
[Bug #11211]
* test/ruby/test_defined.rb: add a test for this fix.
Wed Jun 3 04:14:13 2015 Koichi Sasada <ko1@atdot.net> Wed Jun 3 04:14:13 2015 Koichi Sasada <ko1@atdot.net>
* insns.def (defined), vm_insnhelper.c (vm_defined): * insns.def (defined), vm_insnhelper.c (vm_defined):

Просмотреть файл

@ -208,4 +208,29 @@ class TestDefined < Test::Unit::TestCase
def test_super_toplevel def test_super_toplevel
assert_separately([], "assert_nil(defined?(super))") assert_separately([], "assert_nil(defined?(super))")
end end
class ExampleRespondToMissing
attr_reader :called
def initialize
@called = false
end
def respond_to_missing? *args
@called = true
false
end
def existing_method
end
end
def test_method_by_respond_to_missing
bug_11211 = '[Bug #11211]'
obj = ExampleRespondToMissing.new
assert_equal("method", defined?(obj.existing_method), bug_11211)
assert_equal(false, obj.called, bug_11211)
assert_equal(nil, defined?(obj.non_existing_method), bug_11211)
assert_equal(true, obj.called, bug_11211)
end
end end

Просмотреть файл

@ -2456,15 +2456,12 @@ vm_defined(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_num_t op_type, VALUE
if (me) { if (me) {
const rb_method_definition_t *def = me->def; const rb_method_definition_t *def = me->def;
if (!(def->flag & NOEX_PRIVATE)) { if (!(def->flag & NOEX_PRIVATE) &&
if (!((def->flag & NOEX_PROTECTED) && !((def->flag & NOEX_PROTECTED) && !rb_obj_is_kind_of(GET_SELF(), rb_class_real(klass)))) {
!rb_obj_is_kind_of(GET_SELF(),
rb_class_real(klass)))) {
expr_type = DEFINED_METHOD; expr_type = DEFINED_METHOD;
} }
} }
} else {
{
VALUE args[2]; VALUE args[2];
VALUE r; VALUE r;