function-put: signal error with non-symbol

* lisp/subr.el (function-get): Signal an error if given a non-symbol
for consistency with 'get'.
* test/lisp/subr-tests.el (subr-butlast): Test for the above.
This commit is contained in:
Stefan Kangas 2025-04-01 21:25:33 +02:00
parent 87da719b6c
commit a4ec9ca129
2 changed files with 7 additions and 1 deletions

View file

@ -4639,6 +4639,8 @@ If AUTOLOAD is non-nil and F is autoloaded, try to load it
in the hope that it will set PROP. If AUTOLOAD is `macro', do it only
if it's an autoloaded macro."
(declare (important-return-value t))
(unless (symbolp f)
(signal 'wrong-type-argument (list 'symbolp f)))
(let ((val nil))
(while (and (symbolp f)
(null (setq val (get f prop)))

View file

@ -1298,7 +1298,11 @@ final or penultimate step during initialization."))
(should (eq (function-get 'subr-tests--some-fun 'prop) 'value))
;; With an alias.
(should (eq (function-get 'subr-tests--some-alias 'prop) 'value))
(function-put 'subr-tests--some-alias 'prop 'value))
(function-put 'subr-tests--some-alias 'prop 'value)
(should-error (function-get "non-symbol" 'prop)
:type 'wrong-type-argument)
(should-error (function-put "non-symbol" 'prop 'val)
:type 'wrong-type-argument))
(function-put 'subr-tests--some-fun 'prop nil)))
(defun subr-tests--butlast-ref (list &optional n)