Permalink
Browse files

fix #1823

  • Loading branch information...
1 parent 058bb18 commit d7b179475b3dbdc4fa6441a74e97560936e4942e @ksss ksss committed Mar 8, 2014
Showing with 7 additions and 3 deletions.
  1. +6 −3 src/hash.c
  2. +1 −0 test/t/hash.rb
View
@@ -874,15 +874,14 @@ static mrb_value
hash_equal(mrb_state *mrb, mrb_value hash1, mrb_value hash2, mrb_bool eql)
{
khash_t(ht) *h1, *h2;
+ mrb_bool eq;
if (mrb_obj_equal(mrb, hash1, hash2)) return mrb_true_value();
if (!mrb_hash_p(hash2)) {
if (!mrb_respond_to(mrb, hash2, mrb_intern_lit(mrb, "to_hash"))) {
return mrb_false_value();
}
else {
- mrb_bool eq;
-
if (eql) {
eq = mrb_eql(mrb, hash2, hash1);
}
@@ -908,7 +907,11 @@ hash_equal(mrb_state *mrb, mrb_value hash1, mrb_value hash2, mrb_bool eql)
key = kh_key(h1,k1);
k2 = kh_get(ht, mrb, h2, key);
if (k2 != kh_end(h2)) {
- if (mrb_eql(mrb, kh_value(h1,k1), kh_value(h2,k2))) {
+ if (eql)
+ eq = mrb_eql(mrb, kh_value(h1,k1), kh_value(h2,k2));
+ else
+ eq = mrb_equal(mrb, kh_value(h1,k1), kh_value(h2,k2));
+ if (eq) {
continue; /* next key */
}
}
View
@@ -12,6 +12,7 @@
assert('Hash#==', '15.2.13.4.1') do
assert_true({ 'abc' => 'abc' } == { 'abc' => 'abc' })
assert_false({ 'abc' => 'abc' } == { 'cba' => 'cba' })
+ assert_true({ :equal => 1 } == { :equal => 1.0 })
end
assert('Hash#[]', '15.2.13.4.2') do

0 comments on commit d7b1794

Please sign in to comment.