1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

numeric.c: correct error message when coerce fails

* 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/trunk@49224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2015-01-12 09:56:14 +00:00
parent 77f3125567
commit 34289fff0f
3 changed files with 12 additions and 1 deletions

View file

@ -1,3 +1,9 @@
Mon Jan 12 18:35:44 2015 Eric Wong <e@80x24.org>
* 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
Mon Jan 12 18:01:24 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Jan 12 18:01:24 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/rdoc/text.rb (expand_tabs): get rid of infinite loop with * lib/rdoc/text.rb (expand_tabs): get rid of infinite loop with

View file

@ -3426,10 +3426,11 @@ static int
bit_coerce(VALUE *x, VALUE *y) bit_coerce(VALUE *x, VALUE *y)
{ {
if (!FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) { if (!FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) {
VALUE orig = *x;
do_coerce(x, y, TRUE); do_coerce(x, y, TRUE);
if (!FIXNUM_P(*x) && !RB_TYPE_P(*x, T_BIGNUM) if (!FIXNUM_P(*x) && !RB_TYPE_P(*x, T_BIGNUM)
&& !FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) { && !FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) {
coerce_failed(*x, *y); coerce_failed(orig, *y);
} }
} }
return TRUE; return TRUE;

View file

@ -32,6 +32,10 @@ class TestNumeric < Test::Unit::TestCase
assert_raise_with_message(TypeError, /:"\\u3042"/) {1|:"\u{3042}"} assert_raise_with_message(TypeError, /:"\\u3042"/) {1|:"\u{3042}"}
assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"} assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"}
end end
bug10711 = '[ruby-core:67405] [Bug #10711]'
exp = "Float can't be coerced into Fixnum"
assert_raise_with_message(TypeError, exp, bug10711) { 1 & 1.2 }
end end
def test_dummynumeric def test_dummynumeric