summaryrefslogtreecommitdiff
path: root/test/lisp/emacs-lisp/bytecomp-tests.el
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2022-12-17 14:48:34 +0100
committerMattias EngdegÄrd <mattiase@acm.org>2022-12-18 14:55:02 +0100
commit730a39e8810e91ad3bb70af191229b78c3858983 (patch)
tree8dcaf45d517860136fb2302dd866d4c2a48d6ac5 /test/lisp/emacs-lisp/bytecomp-tests.el
parent68fb06f47fd09d36a3d1d35a4d24bf40489bea19 (diff)
downloademacs-730a39e8810e91ad3bb70af191229b78c3858983.tar.gz
emacs-730a39e8810e91ad3bb70af191229b78c3858983.tar.bz2
emacs-730a39e8810e91ad3bb70af191229b78c3858983.zip
Warn about lambda expressions in comparisons
Lambda expressions are not comparable; warn about calls such as (eq x (lambda ...)) etc. * lisp/emacs-lisp/bytecomp.el (bytecomp--dodgy-eq-arg): Rename to... (bytecomp--dodgy-eq-arg-p): ...this. Use pcase. Add lambda checks. (bytecomp--value-type-description, bytecomp--arg-type-description) (bytecomp--check-eq-args, bytecomp--check-memq-args): Add function checks. Update calls. Make compiler-macro arguments optional to avoid crashes in malformed code. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp--with-warning-test): Simplify argument. Run each compilation with a fresh (empty) warning cache. Add ert-info for easier debugging. (bytecomp-warn-dodgy-args-eq, bytecomp-warn-dodgy-args-memq): Add lambda tests.
Diffstat (limited to 'test/lisp/emacs-lisp/bytecomp-tests.el')
-rw-r--r--test/lisp/emacs-lisp/bytecomp-tests.el20
1 files changed, 14 insertions, 6 deletions
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index 00361a4286b..3400128759a 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -833,15 +833,19 @@ byte-compiled. Run with dynamic binding."
;; Should not warn that mt--test2 is not known to be defined.
(should-not (re-search-forward "my--test2" nil t))))
-(defmacro bytecomp--with-warning-test (re-warning &rest form)
+(defmacro bytecomp--with-warning-test (re-warning form)
(declare (indent 1))
`(with-current-buffer (get-buffer-create "*Compile-Log*")
(let ((inhibit-read-only t)) (erase-buffer))
- (let ((text-quoting-style 'grave))
- (byte-compile ,@form)
- (ert-info ((prin1-to-string (buffer-string)) :prefix "buffer: ")
- (should (re-search-forward
- (string-replace " " "[ \n]+" ,re-warning)))))))
+ (let ((text-quoting-style 'grave)
+ (macroexp--warned
+ (make-hash-table :test #'equal :weakness 'key)) ; oh dear
+ (form ,form))
+ (ert-info ((prin1-to-string form) :prefix "form: ")
+ (byte-compile form)
+ (ert-info ((prin1-to-string (buffer-string)) :prefix "buffer: ")
+ (should (re-search-forward
+ (string-replace " " "[ \n]+" ,re-warning))))))))
(ert-deftest bytecomp-warn-wrong-args ()
(bytecomp--with-warning-test "remq.*3.*2"
@@ -874,6 +878,8 @@ byte-compiled. Run with dynamic binding."
(bytecomp--with-warning-test (msg "list" 1) `(,fn '(a) 'x))
(bytecomp--with-warning-test (msg "string" 2) `(,fn 'x "a"))
(bytecomp--with-warning-test (msg "vector" 2) `(,fn 'x [a]))
+ (bytecomp--with-warning-test (msg "function" 2) `(,fn 'x (lambda () 1)))
+ (bytecomp--with-warning-test (msg "function" 2) `(,fn 'x #'(lambda () 1)))
(unless (eq fn 'eql)
(bytecomp--with-warning-test (msg "integer" 2) `(,fn 'x #x10000000000))
(bytecomp--with-warning-test (msg "float" 2) `(,fn 'x 1.0))))))
@@ -899,6 +905,8 @@ byte-compiled. Run with dynamic binding."
(bytecomp--with-warning-test (msg1 "list") `(,fn '(a) '(x)))
(bytecomp--with-warning-test (msg1 "string") `(,fn "a" '(x)))
(bytecomp--with-warning-test (msg1 "vector") `(,fn [a] '(x)))
+ (bytecomp--with-warning-test (msg1 "function") `(,fn (lambda () 1) '(x)))
+ (bytecomp--with-warning-test (msg1 "function") `(,fn #'(lambda () 1) '(x)))
(unless (eq fn 'memql)
(bytecomp--with-warning-test (msg1 "integer") `(,fn #x10000000000 '(x)))
(bytecomp--with-warning-test (msg1 "float") `(,fn 1.0 '(x))))