Return nil if type differ in `String#<=>`.
authorTakeshi Watanabe <[email protected]>
Sat, 24 Mar 2018 07:18:44 +0000 (24 16:18 +0900)
committerTakeshi Watanabe <[email protected]>
Sat, 24 Mar 2018 07:18:44 +0000 (24 16:18 +0900)
src/string.c
test/t/string.rb

index e8c60a6..469335b 100644 (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);
       }
index a1277ce..e91b915 100644 (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