ruby-changes:54646
From: naruse <ko1@a...>
Date: Fri, 18 Jan 2019 13:19:40 +0900 (JST)
Subject: [ruby-changes:54646] naruse:r66862 (ruby_2_6): merge revision(s) 66796, 66797: [Backport #15525]
naruse 2019-01-18 13:19:32 +0900 (Fri, 18 Jan 2019) New Revision: 66862 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66862 Log: merge revision(s) 66796,66797: [Backport #15525] No TypeError at nil if exception: false [ruby-core:91021] [Bug #15525] No FloatDomainError at non-finitive number if exception: false [ruby-core:91021] [Bug #15525] Modified directories: branches/ruby_2_6/ Modified files: branches/ruby_2_6/complex.c branches/ruby_2_6/object.c branches/ruby_2_6/rational.c branches/ruby_2_6/test/ruby/test_complex.rb branches/ruby_2_6/test/ruby/test_integer.rb branches/ruby_2_6/test/ruby/test_rational.rb branches/ruby_2_6/version.h Index: ruby_2_6/test/ruby/test_integer.rb =================================================================== --- ruby_2_6/test/ruby/test_integer.rb (revision 66861) +++ ruby_2_6/test/ruby/test_integer.rb (revision 66862) @@ -175,6 +175,15 @@ class TestInteger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_6/test/ruby/test_integer.rb#L175 def o.to_int; raise; end assert_equal(nil, Integer(o, exception: false)) } + assert_nothing_raised(FloatDomainError) { + assert_equal(nil, Integer(Float::INFINITY, exception: false)) + } + assert_nothing_raised(FloatDomainError) { + assert_equal(nil, Integer(-Float::INFINITY, exception: false)) + } + assert_nothing_raised(FloatDomainError) { + assert_equal(nil, Integer(Float::NAN, exception: false)) + } assert_raise(ArgumentError) { Integer("1z", exception: true) Index: ruby_2_6/test/ruby/test_complex.rb =================================================================== --- ruby_2_6/test/ruby/test_complex.rb (revision 66861) +++ ruby_2_6/test/ruby/test_complex.rb (revision 66862) @@ -864,9 +864,15 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_6/test/ruby/test_complex.rb#L864 assert_equal(nil, Complex('5x', exception: false)) } assert_nothing_raised(ArgumentError){ + assert_equal(nil, Complex(nil, exception: false)) + } + assert_nothing_raised(ArgumentError){ assert_equal(nil, Complex(Object.new, exception: false)) } assert_nothing_raised(ArgumentError){ + assert_equal(nil, Complex(1, nil, exception: false)) + } + assert_nothing_raised(ArgumentError){ assert_equal(nil, Complex(1, Object.new, exception: false)) } Index: ruby_2_6/test/ruby/test_rational.rb =================================================================== --- ruby_2_6/test/ruby/test_rational.rb (revision 66861) +++ ruby_2_6/test/ruby/test_rational.rb (revision 66862) @@ -816,9 +816,15 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_6/test/ruby/test_rational.rb#L816 assert_equal(nil, Rational("1/0", exception: false)) } assert_nothing_raised(TypeError) { + assert_equal(nil, Rational(nil, exception: false)) + } + assert_nothing_raised(TypeError) { assert_equal(nil, Rational(Object.new, exception: false)) } assert_nothing_raised(TypeError) { + assert_equal(nil, Rational(1, nil, exception: false)) + } + assert_nothing_raised(TypeError) { assert_equal(nil, Rational(1, Object.new, exception: false)) } Index: ruby_2_6/object.c =================================================================== --- ruby_2_6/object.c (revision 66861) +++ ruby_2_6/object.c (revision 66862) @@ -3159,6 +3159,7 @@ rb_convert_to_integer(VALUE val, int bas https://github.com/ruby/ruby/blob/trunk/ruby_2_6/object.c#L3159 double f; if (base != 0) goto arg_error; f = RFLOAT_VALUE(val); + if (!raise_exception && !isfinite(f)) return Qnil; if (FIXABLE(f)) return LONG2FIX((long)f); return rb_dbl2big(f); } Index: ruby_2_6/rational.c =================================================================== --- ruby_2_6/rational.c (revision 66861) +++ ruby_2_6/rational.c (revision 66862) @@ -2561,8 +2561,10 @@ nurat_convert(VALUE klass, VALUE numv, V https://github.com/ruby/ruby/blob/trunk/ruby_2_6/rational.c#L2561 VALUE a1 = numv, a2 = denv; int state; - if (NIL_P(a1) || NIL_P(a2)) + if (NIL_P(a1) || NIL_P(a2)) { + if (!raise) return Qnil; rb_raise(rb_eTypeError, "can't convert nil into Rational"); + } if (RB_TYPE_P(a1, T_COMPLEX)) { if (k_exact_zero_p(RCOMPLEX(a1)->imag)) Index: ruby_2_6/version.h =================================================================== --- ruby_2_6/version.h (revision 66861) +++ ruby_2_6/version.h (revision 66862) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_6/version.h#L1 #define RUBY_VERSION "2.6.1" #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 24 +#define RUBY_PATCHLEVEL 25 #define RUBY_RELEASE_YEAR 2019 #define RUBY_RELEASE_MONTH 1 Index: ruby_2_6/complex.c =================================================================== --- ruby_2_6/complex.c (revision 66861) +++ ruby_2_6/complex.c (revision 66862) @@ -1939,8 +1939,10 @@ to_complex(VALUE val) https://github.com/ruby/ruby/blob/trunk/ruby_2_6/complex.c#L1939 static VALUE nucomp_convert(VALUE klass, VALUE a1, VALUE a2, int raise) { - if (NIL_P(a1) || NIL_P(a2)) + if (NIL_P(a1) || NIL_P(a2)) { + if (!raise) return Qnil; rb_raise(rb_eTypeError, "can't convert nil into Complex"); + } if (RB_TYPE_P(a1, T_STRING)) { a1 = string_to_c_strict(a1, raise); Index: ruby_2_6 =================================================================== --- ruby_2_6 (revision 66861) +++ ruby_2_6 (revision 66862) Property changes on: ruby_2_6 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r66796-66797 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/