]> git.eshelyaron.com Git - emacs.git/commit
Warn about unmatchable constant args to `eq`, `memq` etc
authorMattias Engdegård <mattiase@acm.org>
Wed, 14 Dec 2022 16:48:17 +0000 (17:48 +0100)
committerMattias Engdegård <mattiase@acm.org>
Wed, 14 Dec 2022 18:30:16 +0000 (19:30 +0100)
commit537f78b537ddd56198059bc02b5abc6e51c5b523
treef67ece8cc5bd33502d53bef2e37a35bfbb3b5b42
parent3b573f7d1f583d3c4169fa7d7dc1f4bcd22197c1
Warn about unmatchable constant args to `eq`, `memq` etc

Add a byte-compiler warning about attempts to compare literal values
with undefined identity relation to other values.  For example:

  (eq x 2.0)
  (memq x '("a" (b) [c]))

Such incomparable values include all literal conses, strings, vectors,
records and (except for eql and memql) floats and bignums.
The warning currently applies to eq, eql, memq, memql, assq, rassq,
remq and delq.

* lisp/emacs-lisp/bytecomp.el (bytecomp--dodgy-eq-arg)
(bytecomp--value-type-description, bytecomp--arg-type-description)
(bytecomp--warn-dodgy-eq-arg, bytecomp--check-eq-args)
(bytecomp--check-memq-args): New.
(eq, eql, memq, memql, assq, rassq, remq, delq):
Set compiler-macro property.
* lisp/emacs-lisp/byte-run.el (with-suppressed-warnings):
Amend doc string.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp--with-warning-test): Fix text-quoting-style and expand
re-warning so that it doesn't need to be a literal.
(bytecomp-warn-dodgy-args-eq, bytecomp-warn-dodgy-args-memq):
New tests.
lisp/emacs-lisp/byte-run.el
lisp/emacs-lisp/bytecomp.el
test/lisp/emacs-lisp/bytecomp-tests.el