Fix type error with closure as :TEST in MAKE-HASH-TABLE

This commit is contained in:
Phoebe Goldman 2022-02-03 10:09:32 -05:00 committed by Douglas Katzman
parent 32bac2662e
commit 61b1a8b5cb
3 changed files with 15 additions and 2 deletions

View file

@ -136,7 +136,7 @@
;; The type of hash table this is. Part of the exported interface,
;; as well as needed for the MAKE-LOAD-FORM and PRINT-OBJECT methods.
(test nil :type symbol :read-only t)
(test nil :type (or symbol function) :read-only t)
;; How much to grow the hash table by when it fills up. If an index,
;; then add that amount. If a floating point number, then multiply
;; it by that.

View file

@ -444,7 +444,7 @@ Examples:
(dolist (info *user-hash-table-tests*
(if hash-function
(if (functionp test)
(values -1 (%fun-name test) test nil)
(values -1 test test nil)
(values -1 test (%coerce-callable-to-fun test) nil))
(error "Unknown :TEST for MAKE-HASH-TABLE: ~S" test)))
(destructuring-bind (test-name test-fun hash-fun) info

View file

@ -0,0 +1,13 @@
(with-test (:name (:hash-table :custom-hash-function :closure))
(flet ((equal-p (left right)
(equal left right))
(hash (item)
(sxhash item)))
(let ((table (make-hash-table :test #'equal-p
:hash-function #'hash)))
(loop for i from 0 to 100
do (progn
(setf (gethash i table) i)
(assert (= (gethash i table) i))))
(assert (= (hash-table-count table) 101))
(assert (eq (hash-table-test table) #'equal-p)))))