summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/bytecomp.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emacs-lisp/bytecomp.el')
-rw-r--r--lisp/emacs-lisp/bytecomp.el39
1 files changed, 21 insertions, 18 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 9af32102c06..7571b4d409a 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -5489,24 +5489,27 @@ and corresponding effects."
;; Check for (in)comparable constant values in calls to `eq', `memq' etc.
-(defun bytecomp--dodgy-eq-arg (x number-ok)
+(defun bytecomp--dodgy-eq-arg-p (x number-ok)
"Whether X is a bad argument to `eq' (or `eql' if NUMBER-OK is non-nil)."
- (cond ((consp x) (and (eq (car x) 'quote) (consp (cadr x))))
- ((symbolp x) nil)
- ((integerp x) (not (or (<= -536870912 x 536870911) number-ok)))
- ((floatp x) (not number-ok))
- (t t)))
+ (pcase x
+ ((or `(quote ,(pred consp)) `(function (lambda . ,_))) t)
+ ((or (pred consp) (pred symbolp)) nil)
+ ((pred integerp)
+ (not (or (<= -536870912 x 536870911) number-ok)))
+ ((pred floatp) (not number-ok))
+ (_ t)))
(defun bytecomp--value-type-description (x)
- (cond ((and x (proper-list-p x)) "list")
- ((recordp x) "record")
- (t (symbol-name (type-of x)))))
+ (cond
+ ((proper-list-p x) "list")
+ ((recordp x) "record")
+ (t (symbol-name (type-of x)))))
(defun bytecomp--arg-type-description (x)
- (bytecomp--value-type-description
- (if (and (consp x) (eq (car x) 'quote))
- (cadr x)
- x)))
+ (pcase x
+ (`(function (lambda . ,_)) "function")
+ (`(quote . ,val) (bytecomp--value-type-description val))
+ (_ (bytecomp--value-type-description x))))
(defun bytecomp--warn-dodgy-eq-arg (form type parenthesis)
(macroexp-warn-and-return
@@ -5514,10 +5517,10 @@ and corresponding effects."
(car form) type parenthesis)
form '(suspicious eq) t))
-(defun bytecomp--check-eq-args (form a b &rest _ignore)
+(defun bytecomp--check-eq-args (form &optional a b &rest _ignore)
(let* ((number-ok (eq (car form) 'eql))
- (bad-arg (cond ((bytecomp--dodgy-eq-arg a number-ok) 1)
- ((bytecomp--dodgy-eq-arg b number-ok) 2))))
+ (bad-arg (cond ((bytecomp--dodgy-eq-arg-p a number-ok) 1)
+ ((bytecomp--dodgy-eq-arg-p b number-ok) 2))))
(if bad-arg
(bytecomp--warn-dodgy-eq-arg
form
@@ -5528,11 +5531,11 @@ and corresponding effects."
(put 'eq 'compiler-macro #'bytecomp--check-eq-args)
(put 'eql 'compiler-macro #'bytecomp--check-eq-args)
-(defun bytecomp--check-memq-args (form elem list &rest _ignore)
+(defun bytecomp--check-memq-args (form &optional elem list &rest _ignore)
(let* ((fn (car form))
(number-ok (eq fn 'memql)))
(cond
- ((bytecomp--dodgy-eq-arg elem number-ok)
+ ((bytecomp--dodgy-eq-arg-p elem number-ok)
(bytecomp--warn-dodgy-eq-arg
form (bytecomp--arg-type-description elem) "arg 1"))
((and (consp list) (eq (car list) 'quote)