ruby-changes:37143
From: normal <ko1@a...>
Date: Mon, 12 Jan 2015 18:56:24 +0900 (JST)
Subject: [ruby-changes:37143] normal:r49224 (trunk): numeric.c: correct error message when coerce fails
normal 2015-01-12 18:56:14 +0900 (Mon, 12 Jan 2015) New Revision: 49224 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49224 Log: 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 Modified files: trunk/ChangeLog trunk/numeric.c trunk/test/ruby/test_numeric.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 49223) +++ ChangeLog (revision 49224) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Jan 12 18:35:44 2015 Eric Wong <e@8...> + + * 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@r...> * lib/rdoc/text.rb (expand_tabs): get rid of infinite loop with Index: numeric.c =================================================================== --- numeric.c (revision 49223) +++ numeric.c (revision 49224) @@ -3426,10 +3426,11 @@ static int https://github.com/ruby/ruby/blob/trunk/numeric.c#L3426 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; Index: test/ruby/test_numeric.rb =================================================================== --- test/ruby/test_numeric.rb (revision 49223) +++ test/ruby/test_numeric.rb (revision 49224) @@ -32,6 +32,10 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L32 assert_raise_with_message(TypeError, /:"\\u3042"/) {1|:"\u{3042}"} assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"} 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 def test_dummynumeric -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/