* vm_insnhelper.c (vm_defined): check respond_to_missing?
at defined?(func()). * test/ruby/test_defined.rb: add a test for this fix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50738 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5bcae57c6f
commit
a54da1c050
@ -1,3 +1,10 @@
|
|||||||
|
Wed Jun 3 04:48:05 2015 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* vm_insnhelper.c (vm_defined): check respond_to_missing?
|
||||||
|
at defined?(func()).
|
||||||
|
|
||||||
|
* test/ruby/test_defined.rb: add a test for this fix.
|
||||||
|
|
||||||
Wed Jun 3 04:34:39 2015 Koichi Sasada <ko1@atdot.net>
|
Wed Jun 3 04:34:39 2015 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* vm_insnhelper.c (vm_defined): skip respond_to_missing? when
|
* vm_insnhelper.c (vm_defined): skip respond_to_missing? when
|
||||||
|
@ -223,6 +223,14 @@ class TestDefined < Test::Unit::TestCase
|
|||||||
|
|
||||||
def existing_method
|
def existing_method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def func_defined_existing_func
|
||||||
|
defined?(existing_method())
|
||||||
|
end
|
||||||
|
|
||||||
|
def func_defined_non_existing_func
|
||||||
|
defined?(non_existing_method())
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_method_by_respond_to_missing
|
def test_method_by_respond_to_missing
|
||||||
@ -232,5 +240,12 @@ class TestDefined < Test::Unit::TestCase
|
|||||||
assert_equal(false, obj.called, bug_11211)
|
assert_equal(false, obj.called, bug_11211)
|
||||||
assert_equal(nil, defined?(obj.non_existing_method), bug_11211)
|
assert_equal(nil, defined?(obj.non_existing_method), bug_11211)
|
||||||
assert_equal(true, obj.called, bug_11211)
|
assert_equal(true, obj.called, bug_11211)
|
||||||
|
|
||||||
|
bug_11212 = '[Bug #11212]'
|
||||||
|
obj = ExampleRespondToMissing.new
|
||||||
|
assert_equal("method", obj.func_defined_existing_func, bug_11212)
|
||||||
|
assert_equal(false, obj.called, bug_11212)
|
||||||
|
assert_equal(nil, obj.func_defined_non_existing_func, bug_11212)
|
||||||
|
assert_equal(true, obj.called, bug_11212)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2409,6 +2409,22 @@ FUNC_FASTCALL(rb_vm_opt_struct_aset)(rb_thread_t *th, rb_control_frame_t *reg_cf
|
|||||||
|
|
||||||
/* defined insn */
|
/* defined insn */
|
||||||
|
|
||||||
|
static enum defined_type
|
||||||
|
check_resopnd_to_missing(VALUE obj, VALUE v)
|
||||||
|
{
|
||||||
|
VALUE args[2];
|
||||||
|
VALUE r;
|
||||||
|
|
||||||
|
args[0] = obj; args[1] = Qfalse;
|
||||||
|
r = rb_check_funcall(v, idRespond_to_missing, 2, args);
|
||||||
|
if (r != Qundef && RTEST(r)) {
|
||||||
|
return DEFINED_METHOD;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
vm_defined(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_num_t op_type, VALUE obj, VALUE needstr, VALUE v)
|
vm_defined(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_num_t op_type, VALUE obj, VALUE needstr, VALUE v)
|
||||||
{
|
{
|
||||||
@ -2449,6 +2465,9 @@ vm_defined(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_num_t op_type, VALUE
|
|||||||
if (rb_method_boundp(klass, SYM2ID(obj), 0)) {
|
if (rb_method_boundp(klass, SYM2ID(obj), 0)) {
|
||||||
expr_type = DEFINED_METHOD;
|
expr_type = DEFINED_METHOD;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
expr_type = check_resopnd_to_missing(obj, v);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case DEFINED_METHOD:{
|
case DEFINED_METHOD:{
|
||||||
VALUE klass = CLASS_OF(v);
|
VALUE klass = CLASS_OF(v);
|
||||||
@ -2462,13 +2481,7 @@ vm_defined(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_num_t op_type, VALUE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE args[2];
|
expr_type = check_resopnd_to_missing(obj, v);
|
||||||
VALUE r;
|
|
||||||
|
|
||||||
args[0] = obj; args[1] = Qfalse;
|
|
||||||
r = rb_check_funcall(v, idRespond_to_missing, 2, args);
|
|
||||||
if (r != Qundef && RTEST(r))
|
|
||||||
expr_type = DEFINED_METHOD;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user