1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[Bug #18937] Coerce non-Numeric into Complex at comparisons

This commit is contained in:
Nobuyoshi Nakada 2022-08-22 12:21:47 +09:00
parent d0b17a4d20
commit d5f50463c2
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 5 additions and 2 deletions

View file

@ -1121,7 +1121,10 @@ nucomp_real_p(VALUE self)
static VALUE
nucomp_cmp(VALUE self, VALUE other)
{
if (nucomp_real_p(self) && k_numeric_p(other)) {
if (!k_numeric_p(other)) {
return rb_num_coerce_cmp(self, other, idCmp);
}
if (nucomp_real_p(self)) {
if (RB_TYPE_P(other, T_COMPLEX) && nucomp_real_p(other)) {
get_dat2(self, other);
return rb_funcall(adat->real, idCmp, 1, bdat->real);

View file

@ -579,7 +579,7 @@ class Complex_Test < Test::Unit::TestCase
def test_coerce2
x = ObjectX.new
%w(+ - * / quo **).each do |op|
%w(+ - * / quo ** <=>).each do |op|
assert_kind_of(Numeric, Complex(1).__send__(op, x))
end
end