[Bug #20296] Clear errinfo when exception: false
This commit is contained in:
parent
a1ca96e1fd
commit
dc146babf4
@ -2323,8 +2323,11 @@ nucomp_convert(VALUE klass, VALUE a1, VALUE a2, int raise)
|
||||
return a1;
|
||||
/* should raise exception for consistency */
|
||||
if (!k_numeric_p(a1)) {
|
||||
if (!raise)
|
||||
return rb_protect(to_complex, a1, NULL);
|
||||
if (!raise) {
|
||||
a1 = rb_protect(to_complex, a1, NULL);
|
||||
rb_set_errinfo(Qnil);
|
||||
return a1;
|
||||
}
|
||||
return to_complex(a1);
|
||||
}
|
||||
}
|
||||
|
@ -981,30 +981,16 @@ class Complex_Test < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_Complex_without_exception
|
||||
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))
|
||||
}
|
||||
assert_complex_without_exception('5x')
|
||||
assert_complex_without_exception(nil)
|
||||
assert_complex_without_exception(Object.new)
|
||||
assert_complex_without_exception(1, nil)
|
||||
assert_complex_without_exception(1, Object.new)
|
||||
|
||||
o = Object.new
|
||||
def o.to_c; raise; end
|
||||
assert_nothing_raised(ArgumentError){
|
||||
assert_equal(nil, Complex(o, exception: false))
|
||||
}
|
||||
assert_nothing_raised(ArgumentError){
|
||||
assert_equal(nil, Complex(1, o, exception: false))
|
||||
}
|
||||
assert_complex_without_exception(o)
|
||||
assert_complex_without_exception(1, o)
|
||||
end
|
||||
|
||||
def test_respond
|
||||
@ -1263,4 +1249,13 @@ class Complex_Test < Test::Unit::TestCase
|
||||
Complex.polar(1, obj)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_complex_without_exception(*args)
|
||||
assert_nothing_raised(ArgumentError) do
|
||||
assert_nil(Complex(*args, exception: false))
|
||||
assert_nil($!)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user