ruby-changes:46362
From: eregon <ko1@a...>
Date: Tue, 25 Apr 2017 20:42:48 +0900 (JST)
Subject: [ruby-changes:46362] eregon:r58476 (trunk): no longer rescue exceptions of #<=> when initializing a Range
eregon 2017-04-25 20:42:43 +0900 (Tue, 25 Apr 2017) New Revision: 58476 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58476 Log: no longer rescue exceptions of #<=> when initializing a Range * range.c (range_init): no longer hide the user exception with a ArgumentError, just let the user exception go through. * test/ruby/test_range.rb (test_new): add tests. [Feature #7688] Modified files: trunk/NEWS trunk/range.c trunk/test/ruby/test_range.rb Index: range.c =================================================================== --- range.c (revision 58475) +++ range.c (revision 58476) @@ -34,19 +34,6 @@ static VALUE r_cover_p(VALUE, VALUE, VAL https://github.com/ruby/ruby/blob/trunk/range.c#L34 #define EXCL(r) RTEST(RANGE_EXCL(r)) -static VALUE -range_failed(void) -{ - rb_raise(rb_eArgError, "bad value for range"); - return Qnil; /* dummy */ -} - -static VALUE -range_check(VALUE *args) -{ - return rb_funcall(args[0], id_cmp, 1, args[1]); -} - static void range_init(VALUE range, VALUE beg, VALUE end, VALUE exclude_end) { @@ -58,9 +45,9 @@ range_init(VALUE range, VALUE beg, VALUE https://github.com/ruby/ruby/blob/trunk/range.c#L45 if (!FIXNUM_P(beg) || !FIXNUM_P(end)) { VALUE v; - v = rb_rescue(range_check, (VALUE)args, range_failed, 0); + v = rb_funcall(beg, id_cmp, 1, end); if (NIL_P(v)) - range_failed(); + rb_raise(rb_eArgError, "bad value for range"); } RANGE_SET_EXCL(range, exclude_end); Index: test/ruby/test_range.rb =================================================================== --- test/ruby/test_range.rb (revision 58475) +++ test/ruby/test_range.rb (revision 58476) @@ -9,6 +9,14 @@ class TestRange < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L9 assert_equal((0..2), Range.new(0, 2)) assert_equal((0..2), Range.new(0, 2, false)) assert_equal((0...2), Range.new(0, 2, true)) + + assert_raise(ArgumentError) { (1.."3") } + + obj = Object.new + def obj.<=>(other) + raise RuntimeError, "cmp" + end + assert_raise_with_message(RuntimeError, "cmp") { (obj..3) } end def test_frozen_initialize Index: NEWS =================================================================== --- NEWS (revision 58475) +++ NEWS (revision 58476) @@ -46,6 +46,12 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L46 of #coerce. Return nil in #coerce if the coercion is impossible. [Feature #7688] +* Range + * Range#initialize no longer rescue exceptions when comparing begin and + end with #<=> and raise a "bad value for range" ArgumentError + but instead let the exception from the #<=> call go through. + [Feature #7688] + * Regexp * Update Onigmo 6.1.1. * Support absent operator https://github.com/k-takata/Onigmo/issues/82 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/