bc: fix hash-set key replacement for eq? values

This commit is contained in:
Matthew Flatt 2020-03-06 11:15:50 -07:00
parent 6685120c0a
commit e2c9544ed5
2 changed files with 15 additions and 2 deletions

View File

@ -565,6 +565,18 @@
(check-concurrent-gc-of-keys (lambda (ht proc)
(equal-hash-code ht)))
;; ----------------------------------------
;; Make sure a new `equal?`-based key is used when the "new" value is
;; `eq?` to the old one:
(let ()
(define ht (hash))
(define f (string-copy "apple"))
(define g (string-copy "apple"))
(define ht2 (hash-set (hash-set ht f 1) g 1))
(test 1 hash-count ht2)
(test #t eq? (car (hash-keys ht2)) g))
;; ----------------------------------------
(report-errs)

View File

@ -3467,8 +3467,9 @@ Scheme_Hash_Tree *scheme_hash_tree_set_w_key_wraps(Scheme_Hash_Tree *tree, Schem
return empty_hash_tree[2];
} else
return tree;
} else if (SAME_OBJ(val, mzHAMT_VAL(in_tree, pos))) {
/* Shortcut: setting to the current value */
} else if (SAME_OBJ(val, mzHAMT_VAL(in_tree, pos))
&& SAME_OBJ(key, in_tree->els[pos])) {
/* Shortcut: setting to the current key and value */
return tree;
} else
return hamt_set(tree, h, 0, key, val, 0);