diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-01-17 16:00:11 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-01-17 16:00:11 +0000 |
commit | 636f19193362cd989758044ab6684adce90cf8b2 (patch) | |
tree | 96a8c2032332400bb1ff4ffb19ea09d790977c71 /numeric.c | |
parent | 38921417228bcf683ed5e9aee12765a1dc19be0c (diff) |
merge revision(s) 49224,49234,49235: [Backport #10711]
* numeric.c (bit_coerce): use original value for error message
[ruby-core:67405] [Bug #10711]
* test/ruby/test_numeric.rb (test_coerce): check error message
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@49313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -237,9 +237,14 @@ NORETURN(static void coerce_failed(VALUE x, VALUE y)); static void coerce_failed(VALUE x, VALUE y) { + if (SPECIAL_CONST_P(y) || BUILTIN_TYPE(y) == T_FLOAT) { + y = rb_inspect(y); + } + else { + y = rb_obj_class(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 @@ -3426,10 +3431,11 @@ static int bit_coerce(VALUE *x, VALUE *y) { if (!FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) { + VALUE orig = *x; do_coerce(x, y, TRUE); if (!FIXNUM_P(*x) && !RB_TYPE_P(*x, T_BIGNUM) && !FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) { - coerce_failed(*x, *y); + coerce_failed(orig, *y); } } return TRUE; |