ruby-changes:22976
From: drbrain <ko1@a...>
Date: Thu, 15 Mar 2012 07:13:04 +0900 (JST)
Subject: [ruby-changes:22976] drbrain:r35025 (trunk): * vm_eval.c (check_funcall): Raise ArgumentError if respond_to?
drbrain 2012-03-15 07:12:53 +0900 (Thu, 15 Mar 2012) New Revision: 35025 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35025 Log: * 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. Modified files: trunk/ChangeLog trunk/test/ruby/test_object.rb trunk/vm_eval.c Index: ChangeLog =================================================================== --- ChangeLog (revision 35024) +++ ChangeLog (revision 35025) @@ -1,3 +1,10 @@ +Thu Mar 15 07:03:52 2012 Eric Hodel <drbrain@s...> + + * 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@m...> * include/ruby/intern.h: Add rb_check_arity, rb_error_arity [#6085] Index: vm_eval.c =================================================================== --- vm_eval.c (revision 35024) +++ vm_eval.c (revision 35025) @@ -272,8 +272,11 @@ 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; if (!RTEST(vm_call0(th, recv, idRespond_to, arity, args, me))) { Index: test/ruby/test_object.rb =================================================================== --- test/ruby/test_object.rb (revision 35024) +++ test/ruby/test_object.rb (revision 35025) @@ -460,6 +460,24 @@ 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]' -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/