summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2024-05-29 11:00:27 -0700
committerTakashi Kokubun <[email protected]>2024-05-29 11:00:27 -0700
commit8f1084db9b07cb74f99de70d6f8bb6076d27d8aa (patch)
treea5692cdca7e561f7b15721f042465bb3525ce718
parent22c1e5f126db8e057bdb48d91aa5ae449e019226 (diff)
merge revision(s) dc146babf47a84bbd1f176d766637d4a40327019,f23d5028059078a346efc977287b669d494a5a3f,a0f7de814ae5c299d6ce99bed5fb308a05d50ba0: [Backport #20296]
[Bug #20296] Clear errinfo when `exception: false` [Bug #20296] Refine the test [Bug #20296] Fix the default assertion message
-rw-r--r--complex.c7
-rw-r--r--test/ruby/test_complex.rb40
-rw-r--r--version.h2
3 files changed, 24 insertions, 25 deletions
diff --git a/complex.c b/complex.c
index d29189e367..b6fbc856f1 100644
--- a/complex.c
+++ b/complex.c
@@ -2321,8 +2321,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);
}
}
diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb
index 5cd17d9205..8817a62873 100644
--- a/test/ruby/test_complex.rb
+++ b/test/ruby/test_complex.rb
@@ -980,31 +980,27 @@ 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))
- }
+ def assert_complex_with_exception(error, *args, message: "")
+ assert_raise(error, message) do
+ Complex(*args, exception: true)
+ end
+ assert_nothing_raised(error, message) do
+ assert_nil(Complex(*args, exception: false))
+ assert_nil($!)
+ end
+ end
+
+ def test_Complex_with_exception
+ assert_complex_with_exception(ArgumentError, '5x')
+ assert_complex_with_exception(TypeError, nil)
+ assert_complex_with_exception(TypeError, Object.new)
+ assert_complex_with_exception(TypeError, 1, nil)
+ assert_complex_with_exception(TypeError, 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_with_exception(RuntimeError, o)
+ assert_complex_with_exception(TypeError, 1, o)
end
def test_respond
diff --git a/version.h b/version.h
index beff9a3d4e..a7495506e9 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 1
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 62
+#define RUBY_PATCHLEVEL 63
#include "ruby/version.h"
#include "ruby/internal/abi.h"