mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
No TypeError at nil if exception: false
[ruby-core:91021] [Bug #15525] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
52a97e36d0
commit
62c17a2f21
4 changed files with 18 additions and 2 deletions
|
@ -1943,8 +1943,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);
|
||||
|
|
|
@ -2559,8 +2559,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))
|
||||
|
|
|
@ -865,9 +865,15 @@ class Complex_Test < Test::Unit::TestCase
|
|||
assert_nothing_raised(ArgumentError){
|
||||
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))
|
||||
}
|
||||
|
|
|
@ -815,9 +815,15 @@ class Rational_Test < Test::Unit::TestCase
|
|||
assert_nothing_raised(ZeroDivisionError) {
|
||||
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))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue