ruby-changes:73015
From: Nobuyoshi <ko1@a...>
Date: Mon, 22 Aug 2022 16:29:38 +0900 (JST)
Subject: [ruby-changes:73015] d5f50463c2 (master): [Bug #18937] Coerce non-Numeric into Complex at comparisons
https://git.ruby-lang.org/ruby.git/commit/?id=d5f50463c2 From d5f50463c2b5c5263aa45c58f3f4ec73de8868d5 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 22 Aug 2022 12:21:47 +0900 Subject: [Bug #18937] Coerce non-Numeric into Complex at comparisons --- complex.c | 5 ++++- test/ruby/test_complex.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/complex.c b/complex.c index d625ced7fa..ae40fa7355 100644 --- a/complex.c +++ b/complex.c @@ -1121,7 +1121,10 @@ nucomp_real_p(VALUE self) https://github.com/ruby/ruby/blob/trunk/complex.c#L1121 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); diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb index a3a7546575..f85bf101e0 100644 --- a/test/ruby/test_complex.rb +++ b/test/ruby/test_complex.rb @@ -579,7 +579,7 @@ class Complex_Test < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L579 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 -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/