Raise error on failed comparison in `sort`; ref #4307

parent 73091ab2
......@@ -213,7 +213,11 @@ class Array
if left + 1 == right
lval = self[left]
rval = self[right]
if (block&.call(lval, rval) || (lval <=> rval)) > 0
cmp = if block then block.call(lval,rval) else lval <=> rval end
if cmp.nil?
raise ArgumentError, "comparison of #{lval.inspect} and #{rval.inspect} failed"
end
if cmp > 0
self[left] = rval
self[right] = lval
end
......@@ -245,7 +249,11 @@ class Array
else
lval = lary[lidx]
rval = self[ridx]
if (block&.call(lval, rval) || (lval <=> rval)) <= 0
cmp = if block then block.call(lval,rval) else lval <=> rval end
if cmp.nil?
raise ArgumentError, "comparison of #{lval.inspect} and #{rval.inspect} failed"
end
if cmp <= 0
self[i] = lval
lidx += 1
else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment