Skip to content

Commit 26f65f1

Browse files
committed
improve hash/c error message when non-flat-key applied to non-equal?-hash
1 parent cfa9918 commit 26f65f1

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

typed-racket-lib/typed-racket/utils/hash-contract.rkt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
(and/c hash? hash-weak? (hash/c/check-key k v #:immutable #f)))
2424

2525
(define (hash/c/check-key k v #:immutable [immutable 'dont-care])
26-
;; TODO if (flat-contract? k), then make a contract that produces a "good"
27-
;; error message given a hashtable that is not a `hash-equal?`
28-
(hash/c k v #:immutable immutable))
26+
(if (flat-contract? k)
27+
(hash/c k v #:immutable immutable)
28+
(and/c (flat-named-contract
29+
"hash-equal? (because the key contract is not a flat contract)"
30+
hash-equal?)
31+
(hash/c k v #:immutable immutable))))

typed-racket-test/succeed/issue-625.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
(require 't rackunit)
1313

14-
(define err-regexp #rx"expected equal\\?-based hash")
14+
(define err-regexp #rx"hash-equal\\?.*key contract is not a flat contract")
1515

1616
(check-exn err-regexp
1717
(λ () (give-me-a-hash (hasheqv))))

0 commit comments

Comments
 (0)