diff --git a/ChangeLog b/ChangeLog index eea20bc4bced66..98ddd6b2d78dbd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Wed Feb 15 10:25:22 2012 Naohisa Goto + + * vm_eval.c (check_funcall): set array elements one-by-one to fix + compile error with Fujitsu C Compiler 5.6 on Solaris 10 on Sparc. + +Wed Feb 15 10:25:22 2012 Nobuyoshi Nakada + + * test/ruby/test_object.rb: tests that respond_to? returns false. + +Wed Feb 15 10:25:22 2012 Nobuyoshi Nakada + + * vm_eval.c (check_funcall): try respond_to? first if redefined. + [Bug #5158] + Wed Feb 15 07:15:50 2012 Nobuyoshi Nakada * compile.c (defined_expr): guard the whole expression. diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index db34d144792a6e..d33b9f63412d23 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -181,18 +181,30 @@ def test_convert_type o = Object.new def o.to_s; 1; end assert_raise(TypeError) { String(o) } + def o.to_s; "o"; end + assert_equal("o", String(o)) + def o.respond_to?(*) false; end + assert_raise(TypeError) { String(o) } end def test_check_convert_type o = Object.new def o.to_a; 1; end assert_raise(TypeError) { Array(o) } + def o.to_a; [1]; end + assert_equal([1], Array(o)) + def o.respond_to?(*) false; end + assert_equal([o], Array(o)) end def test_to_integer o = Object.new def o.to_i; nil; end assert_raise(TypeError) { Integer(o) } + def o.to_i; 42; end + assert_equal(42, Integer(o)) + def o.respond_to?(*) false; end + assert_raise(TypeError) { Integer(o) } end class MyInteger @@ -383,6 +395,31 @@ def method_missing(id,*args) end end + def test_implicit_respond_to + bug5158 = '[ruby-core:38799]' + + p = Object.new + + called = [] + p.singleton_class.class_eval do + define_method(:to_ary) do + called << [:to_ary, bug5158] + end + end + [[p]].flatten + assert_equal([[:to_ary, bug5158]], called, bug5158) + + 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, true]], called, bug5158) + end + def test_method_missing_passed_block bug5731 = '[ruby-dev:44961]' diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index efd5a269fdb552..3cac94a1008912 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -787,7 +787,7 @@ def test_attr_source_location end def test_splat_without_respond_to - def (obj = Object.new).respond_to?(m); false end + def (obj = Object.new).respond_to?(m,*); false end [obj].each do |a, b| assert_equal([obj, nil], [a, b], '[ruby-core:24139]') end diff --git a/version.h b/version.h index 9066c06cd64d4d..619c81b690db3b 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 117 +#define RUBY_PATCHLEVEL 118 #define RUBY_RELEASE_DATE "2012-02-15" #define RUBY_RELEASE_YEAR 2012 diff --git a/vm_eval.c b/vm_eval.c index a7e15918b57444..cfa75a46b30acc 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -204,7 +204,7 @@ stack_check(void) } static inline rb_method_entry_t *rb_search_method_entry(VALUE recv, ID mid); -static inline int rb_method_call_status(rb_thread_t *th, rb_method_entry_t *me, call_type scope, VALUE self); +static inline int rb_method_call_status(rb_thread_t *th, const rb_method_entry_t *me, call_type scope, VALUE self); #define NOEX_OK NOEX_NOSUPER /*! @@ -266,12 +266,26 @@ check_funcall_failed(struct rescue_funcall_args *args, VALUE e) static VALUE check_funcall(VALUE recv, ID mid, int argc, VALUE *argv) { - rb_method_entry_t *me = rb_search_method_entry(recv, mid); + VALUE klass = CLASS_OF(recv); + const rb_method_entry_t *me; rb_thread_t *th = GET_THREAD(); - int call_status = rb_method_call_status(th, me, CALL_FCALL, Qundef); + int call_status; + + me = rb_method_entry(klass, idRespond_to); + if (me && !(me->flag & NOEX_BASIC)) { + VALUE args[2]; + + args[0] = ID2SYM(mid); + args[1] = Qtrue; + if (!RTEST(vm_call0(th, recv, idRespond_to, 2, args, me))) { + return Qundef; + } + } + me = rb_search_method_entry(recv, mid); + call_status = rb_method_call_status(th, me, CALL_FCALL, Qundef); if (call_status != NOEX_OK) { - if (rb_method_basic_definition_p(CLASS_OF(recv), idMethodMissing)) { + if (rb_method_basic_definition_p(klass, idMethodMissing)) { return Qundef; } else { @@ -376,7 +390,7 @@ rb_search_method_entry(VALUE recv, ID mid) } static inline int -rb_method_call_status(rb_thread_t *th, rb_method_entry_t *me, call_type scope, VALUE self) +rb_method_call_status(rb_thread_t *th, const rb_method_entry_t *me, call_type scope, VALUE self) { VALUE klass; ID oid;