From: Eric Wong Date: 2015-01-12T21:30:25+00:00 Subject: [ruby-core:67555] Re: [ruby-cvs:56375] usa:r49225 (trunk): * test/ruby/test_numeric.rb (TestNumeric#test_coerce): fixed wrong message. Oops, r49225 is a 64-bit specific change and my original r49224 was only tested on 32-bit. How about making error messages consistent across platforms? Subject: [PATCH] numeric: use consistent message for 32 and 64-bit rb_special_const_p is true for flonum, but 32-bit platforms do not have flonum support, so we show the class name instead. * numeric.c (coerce_failed): consistent message for 32 and 64-bit * test/ruby/test_numeric.rb (test_coerce): fix for 32-bit --- numeric.c | 9 +++++++-- test/ruby/test_numeric.rb | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/numeric.c b/numeric.c index 7458797..a8a0024 100644 --- a/numeric.c +++ b/numeric.c @@ -237,9 +237,14 @@ NORETURN(static void coerce_failed(VALUE x, VALUE y)); static void coerce_failed(VALUE x, VALUE y) { + if (!rb_special_const_p(y) || FLONUM_P(y)) { + y = rb_obj_class(y); + } + else { + y = rb_inspect(y); + } rb_raise(rb_eTypeError, "%"PRIsVALUE" can't be coerced into %"PRIsVALUE, - (rb_special_const_p(y)? rb_inspect(y) : rb_obj_class(y)), - rb_obj_class(x)); + y, rb_obj_class(x)); } static VALUE diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb index 4c94c69..9c5d762 100644 --- a/test/ruby/test_numeric.rb +++ b/test/ruby/test_numeric.rb @@ -34,7 +34,7 @@ class TestNumeric < Test::Unit::TestCase end bug10711 = '[ruby-core:67405] [Bug #10711]' - exp = "1.2 can't be coerced into Fixnum" + exp = "Float can't be coerced into Fixnum" assert_raise_with_message(TypeError, exp, bug10711) { 1 & 1.2 } end -- EW