summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-14 22:12:53 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-14 22:12:53 +0000
commit724e683e86f19cda02dfe3906fdf5adca539b94b (patch)
treeee6467c8d49e7a960d652a4db0868fb0de5f72aa
parent7316302483182a73136b00ad368585e551cbd86f (diff)
* vm_eval.c (check_funcall): Raise ArgumentError if respond_to?
requires more than three arguments. [Bug #6000] * test/ruby/test_object.rb (class TestObject): Test for respond_to? requiring more than three arguments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--test/ruby/test_object.rb18
-rw-r--r--vm_eval.c5
3 files changed, 29 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index d5a9230e91..59f28ca57c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Mar 15 07:03:52 2012 Eric Hodel <drbrain@segment7.net>
+
+ * vm_eval.c (check_funcall): Raise ArgumentError if respond_to?
+ requires more than three arguments. [Bug #6000]
+ * test/ruby/test_object.rb (class TestObject): Test for respond_to?
+ requiring more than three arguments.
+
Thu Mar 15 06:08:06 2012 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* include/ruby/intern.h: Add rb_check_arity, rb_error_arity [#6085]
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index f4a38e0ee3..271ab600a2 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -460,6 +460,24 @@ class TestObject < Test::Unit::TestCase
assert_equal([[:respond_to?, :to_ary]], called, '[bug:6000]')
end
+ def test_implicit_respond_to_arity_3
+ p = Object.new
+
+ called = []
+ p.singleton_class.class_eval do
+ define_method(:respond_to?) do |a, b, c|
+ called << [:respond_to?, a, b, c]
+ false
+ end
+ end
+
+ e = assert_raises(ArgumentError, '[bug:6000]') do
+ [[p]].flatten
+ end
+
+ assert_equal('respond_to? must accept 1 or 2 arguments (requires 3)', e.message)
+ end
+
def test_method_missing_passed_block
bug5731 = '[ruby-dev:44961]'
diff --git a/vm_eval.c b/vm_eval.c
index 8bad08944d..398c344bc5 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -272,7 +272,10 @@ check_funcall(VALUE recv, ID mid, int argc, VALUE *argv)
VALUE args[2];
int arity = rb_method_entry_arity(me);
- if (arity < 1 || arity > 3) arity = 2;
+ if (arity > 2)
+ rb_raise(rb_eArgError, "respond_to? must accept 1 or 2 arguments (requires %d)", arity);
+
+ if (arity < 1) arity = 2;
args[0] = ID2SYM(mid);
args[1] = Qtrue;