[前][次][番号順一覧][スレッド一覧]

ruby-changes:46361

From: eregon <ko1@a...>
Date: Tue, 25 Apr 2017 20:42:36 +0900 (JST)
Subject: [ruby-changes:46361] eregon:r58475 (trunk): no longer rescue exceptions of #coerce in Integer#step

eregon	2017-04-25 20:42:31 +0900 (Tue, 25 Apr 2017)

  New Revision: 58475

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58475

  Log:
    no longer rescue exceptions of #coerce in Integer#step
    
    * numeric.c (num_step_negative_p): no more error hiding.
    * test/ruby/test_float.rb, test/ruby/test_numeric.rb:
      follow the change. [Feature #7688]

  Modified files:
    trunk/NEWS
    trunk/numeric.c
    trunk/test/ruby/test_float.rb
    trunk/test/ruby/test_numeric.rb
Index: test/ruby/test_numeric.rb
===================================================================
--- test/ruby/test_numeric.rb	(revision 58474)
+++ test/ruby/test_numeric.rb	(revision 58475)
@@ -261,8 +261,8 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L261
     assert_raise(ArgumentError) { 1.step(10, 1, 0).size }
     assert_raise(ArgumentError) { 1.step(10, 0) { } }
     assert_raise(ArgumentError) { 1.step(10, 0).size }
-    assert_raise(TypeError) { 1.step(10, "1") { } }
-    assert_raise(TypeError) { 1.step(10, "1").size }
+    assert_raise(ArgumentError) { 1.step(10, "1") { } }
+    assert_raise(ArgumentError) { 1.step(10, "1").size }
     assert_raise(TypeError) { 1.step(10, nil) { } }
     assert_raise(TypeError) { 1.step(10, nil).size }
     assert_nothing_raised { 1.step(by: 0, to: nil) }
Index: test/ruby/test_float.rb
===================================================================
--- test/ruby/test_float.rb	(revision 58474)
+++ test/ruby/test_float.rb	(revision 58475)
@@ -788,7 +788,7 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L788
   end
 
   def test_num2dbl
-    assert_raise(TypeError) do
+    assert_raise(ArgumentError, "comparison of String with 0 failed") do
       1.0.step(2.0, "0.5") {}
     end
     assert_raise(TypeError) do
Index: numeric.c
===================================================================
--- numeric.c	(revision 58474)
+++ numeric.c	(revision 58475)
@@ -446,12 +446,6 @@ coerce_failed(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L446
 	     y, rb_obj_class(x));
 }
 
-static VALUE
-coerce_rescue_quiet(VALUE arg, VALUE errinfo)
-{
-    return Qundef;
-}
-
 static int
 do_coerce(VALUE *x, VALUE *y, int err)
 {
@@ -2585,17 +2579,11 @@ ruby_num_interval_step_size(VALUE from, https://github.com/ruby/ruby/blob/trunk/numeric.c#L2579
     }
 }
 
-static VALUE
-num_step_compare_with_zero(VALUE num)
-{
-    VALUE zero = INT2FIX(0);
-    return rb_check_funcall(num, '>', 1, &zero);
-}
-
 static int
 num_step_negative_p(VALUE num)
 {
     const ID mid = '<';
+    VALUE zero = INT2FIX(0);
     VALUE r;
 
     if (FIXNUM_P(num)) {
@@ -2606,7 +2594,8 @@ num_step_negative_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2594
 	if (method_basic_p(rb_cInteger))
 	    return BIGNUM_NEGATIVE_P(num);
     }
-    r = rb_rescue(num_step_compare_with_zero, num, coerce_rescue_quiet, Qnil);
+
+    r = rb_check_funcall(num, '>', 1, &zero);
     if (r == Qundef) {
 	coerce_failed(num, INT2FIX(0));
     }
Index: NEWS
===================================================================
--- NEWS	(revision 58474)
+++ NEWS	(revision 58475)
@@ -28,6 +28,8 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L28
 * Integer
 
   * Integer.sqrt  [Feature #13219]
+  * Integer#step does no longer rescue exceptions when given
+    a step value which cannot be compared with #> to 0. [Feature #7688]
 
 * IO
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]