Merge pull request #3982 from take-cheeze/fix_str_cmp

Return nil if type differ in `String#<=>`.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2018-03-24 16:27:22 +09:00
committed by GitHub
2 changed files with 2 additions and 1 deletions
+1 -1
View File
@@ -926,7 +926,7 @@ mrb_str_cmp_m(mrb_state *mrb, mrb_value str1)
else {
mrb_value tmp = mrb_funcall(mrb, str2, "<=>", 1, str1);
if (!mrb_nil_p(tmp)) return mrb_nil_value();
if (mrb_nil_p(tmp)) return mrb_nil_value();
if (!mrb_fixnum_p(tmp)) {
return mrb_funcall(mrb, mrb_fixnum_value(0), "-", 1, tmp);
}
+1
View File
@@ -20,6 +20,7 @@ assert('String#<=>', '15.2.10.5.1') do
assert_equal 1, c
assert_equal(-1, d)
assert_equal 1, e
assert_nil 'a' <=> 1024
end
assert('String#==', '15.2.10.5.2') do