improve hash/c error message when non-flat-key applied to non-equal?-hash

This commit is contained in:
Ben Greenman 2017-10-06 16:59:08 -04:00
parent cfa9918ac5
commit 26f65f13f7
2 changed files with 7 additions and 4 deletions

View File

@ -23,6 +23,9 @@
(and/c hash? hash-weak? (hash/c/check-key k v #:immutable #f)))
(define (hash/c/check-key k v #:immutable [immutable 'dont-care])
;; TODO if (flat-contract? k), then make a contract that produces a "good"
;; error message given a hashtable that is not a `hash-equal?`
(hash/c k v #:immutable immutable))
(if (flat-contract? k)
(hash/c k v #:immutable immutable)
(and/c (flat-named-contract
"hash-equal? (because the key contract is not a flat contract)"
hash-equal?)
(hash/c k v #:immutable immutable))))

View File

@ -11,7 +11,7 @@
(require 't rackunit)
(define err-regexp #rx"expected equal\\?-based hash")
(define err-regexp #rx"hash-equal\\?.*key contract is not a flat contract")
(check-exn err-regexp
(λ () (give-me-a-hash (hasheqv))))