summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-11 19:15:36 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-11 19:15:36 +0000
commit691a3a2bdc3495860405b1173d9081804a55c350 (patch)
treee7fb011ce7b8a53572be68e256ab906088d59881
parent3ab9be9245c1e49ee40c4e7b728feddc2368fbd0 (diff)
* vm_eval.c (check_funcall): Call respond_to? with matching arity for
legacy single-argument implementations. [ruby-trunk - Bug #6000] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_object.rb14
-rw-r--r--vm_eval.c5
3 files changed, 23 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 3c00b060d7..dabb7125e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Feb 12 03:14:40 2012 Eric Hodel <drbrain@segment7.net>
+
+ * vm_eval.c (check_funcall): Call respond_to? with matching arity for
+ legacy single-argument implementations. [ruby-trunk - Bug #6000]
+
Sat Feb 11 12:04:05 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compile.c (defined_expr): guard the whole expression.
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index 08d85559c4..eca1be78d5 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -446,6 +446,20 @@ class TestObject < Test::Unit::TestCase
assert_equal([[:respond_to?, :to_ary, true]], called, bug5158)
end
+ def test_implicit_respond_to_arity_1
+ p = Object.new
+
+ called = []
+ p.singleton_class.class_eval do
+ define_method(:respond_to?) do |a|
+ called << [:respond_to?, a]
+ false
+ end
+ end
+ [[p]].flatten
+ assert_equal([[:respond_to?, :to_ary]], called, '[bug:6000]')
+ end
+
def test_method_missing_passed_block
bug5731 = '[ruby-dev:44961]'
diff --git a/vm_eval.c b/vm_eval.c
index a53f8f614c..aa326216b9 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -274,10 +274,13 @@ check_funcall(VALUE recv, ID mid, int argc, VALUE *argv)
me = rb_method_entry(klass, idRespond_to);
if (me && !(me->flag & NOEX_BASIC)) {
VALUE args[2];
+ int arity = rb_method_entry_arity(me);
+
+ if (arity < 1 || arity > 3) arity = 2;
args[0] = ID2SYM(mid);
args[1] = Qtrue;
- if (!RTEST(vm_call0(th, recv, idRespond_to, 2, args, me))) {
+ if (!RTEST(vm_call0(th, recv, idRespond_to, arity, args, me))) {
return Qundef;
}
}