ruby-changes:63254
From: Nobuyoshi <ko1@a...>
Date: Fri, 2 Oct 2020 13:25:30 +0900 (JST)
Subject: [ruby-changes:63254] 89ca842dcc (master): Ensure that the comparison succeeded [Bug #17205]
https://git.ruby-lang.org/ruby.git/commit/?id=89ca842dcc From 89ca842dcce7f05942e2d7be3edc404c9556cafd Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 2 Oct 2020 10:57:07 +0900 Subject: Ensure that the comparison succeeded [Bug #17205] diff --git a/numeric.c b/numeric.c index 6d4eb86..a767c12 100644 --- a/numeric.c +++ b/numeric.c @@ -1518,7 +1518,9 @@ flo_cmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1518 MJIT_FUNC_EXPORTED int rb_float_cmp(VALUE x, VALUE y) { - return NUM2INT(flo_cmp(x, y)); + VALUE c = flo_cmp(x, y); + if (NIL_P(c)) rb_cmperr(x, y); + return NUM2INT(c); } /* diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 64bcf9f..5d17852 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -1648,6 +1648,13 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L1648 TEST end + def test_sort_uncomparable + assert_raise(ArgumentError) {[1, Float::NAN].sort} + assert_raise(ArgumentError) {[1.0, Float::NAN].sort} + assert_raise(ArgumentError) {[Float::NAN, 1].sort} + assert_raise(ArgumentError) {[Float::NAN, 1.0].sort} + end + def test_to_a a = @cls[ 1, 2, 3 ] a_id = a.__id__ @@ -1768,6 +1775,13 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L1775 assert_same(obj, [obj, 1.0].min) end + def test_min_uncomparable + assert_raise(ArgumentError) {[1, Float::NAN].min} + assert_raise(ArgumentError) {[1.0, Float::NAN].min} + assert_raise(ArgumentError) {[Float::NAN, 1].min} + assert_raise(ArgumentError) {[Float::NAN, 1.0].min} + end + def test_max assert_equal(1, [1].max) assert_equal(3, [1, 2, 3, 1, 2].max) @@ -1791,6 +1805,13 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L1805 assert_same(obj, [obj, 1.0].max) end + def test_max_uncomparable + assert_raise(ArgumentError) {[1, Float::NAN].max} + assert_raise(ArgumentError) {[1.0, Float::NAN].max} + assert_raise(ArgumentError) {[Float::NAN, 1].max} + assert_raise(ArgumentError) {[Float::NAN, 1.0].max} + end + def test_minmax assert_equal([3, 3], [3].minmax) assert_equal([1, 3], [1, 2, 3, 1, 2].minmax) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/