Hi,

(12/01/09 22:02), Nikolai Weibull wrote:
> The fix should be to also check the #class of obj against the #class
> of exc, not to simply ignore it if the rb_obj_class()es don”Ēt match.
> I”Ēve attached a patch.

Fixnum#== works fine with Delegator because of implicit conversion, so
I think Exception should also use same way.


diff --git a/error.c b/error.c index 6844f99..7185d52 100644 --- a/error.c +++ b/error.c @@ -732,10 +732,14 @@ exc_equal(VALUE exc, VALUE obj) CONST_ID(id_mesg, "mesg"); if (rb_obj_class(exc) != rb_obj_class(obj)) { - ID id_message, id_backtrace; + ID id_message, id_backtrace, id_exception; CONST_ID(id_message, "message"); CONST_ID(id_backtrace, "backtrace"); + CONST_ID(id_exception, "exception"); + obj = rb_check_funcall(obj, id_exception, 0, 0); + if (obj == Qundef) return Qfalse; + if (rb_obj_class(exc) != rb_obj_class(obj)) return Qfalse; mesg = rb_check_funcall(obj, id_message, 0, 0); if (mesg == Qundef) return Qfalse; backtrace = rb_check_funcall(obj, id_backtrace, 0, 0); diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 028391d..7226fe2 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -380,4 +380,9 @@ end.join load(t.path) end end + + def test_equal + assert_equal(RuntimeError.new("a"), RuntimeError.new("a")) + assert_not_equal(RuntimeError.new("a"), StandardError.new("a")) + end end
-- Nobu Nakada