summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-18 04:19:32 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-18 04:19:32 +0000
commit283b3d8f99c01a13e727b2edf0a7643a67d16361 (patch)
treef1e2753826bda61aa0e0f259163dd0641c813434
parentb9289589d66efec4a5953e8a964019201aaeca9e (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@66862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--complex.c4
-rw-r--r--object.c1
-rw-r--r--rational.c4
-rw-r--r--test/ruby/test_complex.rb6
-rw-r--r--test/ruby/test_integer.rb9
-rw-r--r--test/ruby/test_rational.rb6
-rw-r--r--version.h2
7 files changed, 29 insertions, 3 deletions
diff --git a/complex.c b/complex.c
index ab50daabaf..cc798cccca 100644
--- a/complex.c
+++ b/complex.c
@@ -1939,8 +1939,10 @@ to_complex(VALUE val)
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);
diff --git a/object.c b/object.c
index a60626b5a1..1c0ddfb356 100644
--- a/object.c
+++ b/object.c
@@ -3159,6 +3159,7 @@ rb_convert_to_integer(VALUE val, int base, int raise_exception)
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);
}
diff --git a/rational.c b/rational.c
index 236bc08e39..435a68f421 100644
--- a/rational.c
+++ b/rational.c
@@ -2561,8 +2561,10 @@ nurat_convert(VALUE klass, VALUE numv, VALUE denv, int raise)
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))
diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb
index 4aa3eda1d4..0161ce8ffe 100644
--- a/test/ruby/test_complex.rb
+++ b/test/ruby/test_complex.rb
@@ -864,9 +864,15 @@ class Complex_Test < Test::Unit::TestCase
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))
}
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb
index a73992787d..69347b6b11 100644
--- a/test/ruby/test_integer.rb
+++ b/test/ruby/test_integer.rb
@@ -175,6 +175,15 @@ class TestInteger < Test::Unit::TestCase
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)
diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb
index b289753347..a8cdf22a49 100644
--- a/test/ruby/test_rational.rb
+++ b/test/ruby/test_rational.rb
@@ -816,9 +816,15 @@ class Rational_Test < Test::Unit::TestCase
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))
}
diff --git a/version.h b/version.h
index d5480875c5..f84f5317e2 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#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