]> git.eshelyaron.com Git - emacs.git/commitdiff
Warn about wrong number of args for subrs (Bug#35767)
authorNoam Postavsky <npostavs@gmail.com>
Tue, 28 May 2019 00:36:41 +0000 (20:36 -0400)
committerNoam Postavsky <npostavs@gmail.com>
Thu, 30 May 2019 22:46:07 +0000 (18:46 -0400)
* lisp/emacs-lisp/bytecomp.el (byte-compile-callargs-warn): Don't
assume byte-compile-fdefinition will return non-nil.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-warn-wrong-args)
(bytecomp-warn-wrong-args-subr): New tests.

lisp/emacs-lisp/bytecomp.el
test/lisp/emacs-lisp/bytecomp-tests.el

index 9ea4179b68d65d054446e9105598d5740ec710fc..72e81a653c70f4b91b7222310fd75f0ede690d64 100644 (file)
@@ -1379,7 +1379,7 @@ when printing the error message."
 (defun byte-compile-callargs-warn (form)
   (let* ((def (or (byte-compile-fdefinition (car form) nil)
                  (byte-compile-fdefinition (car form) t)))
-        (sig (byte-compile--function-signature def))
+         (sig (byte-compile--function-signature (or def (car form))))
         (ncall (length (cdr form))))
     ;; Check many or unevalled from subr-arity.
     (if (and (cdr-safe sig)
index bc28c5a6a00d42bc7c7ce704d30bea1804e2bdbb..c399f65b402306c298c6965abdb1ba6d39324fd4 100644 (file)
@@ -438,6 +438,20 @@ Subtests signal errors if something goes wrong."
     ;; Should not warn that mt--test2 is not known to be defined.
     (should-not (re-search-forward "my--test2" nil t))))
 
+(ert-deftest bytecomp-warn-wrong-args ()
+  (with-current-buffer (get-buffer-create "*Compile-Log*")
+    (let ((inhibit-read-only t)) (erase-buffer))
+    (byte-compile '(remq 1 2 3))
+    (ert-info ((buffer-string) :prefix "buffer: ")
+      (should (re-search-forward "remq.*3.*2")))))
+
+(ert-deftest bytecomp-warn-wrong-args-subr ()
+  (with-current-buffer (get-buffer-create "*Compile-Log*")
+    (let ((inhibit-read-only t)) (erase-buffer))
+    (byte-compile '(safe-length 1 2 3))
+    (ert-info ((buffer-string) :prefix "buffer: ")
+      (should (re-search-forward "safe-length.*3.*1")))))
+
 (ert-deftest test-eager-load-macro-expansion ()
   (test-byte-comp-compile-and-load nil
     '(progn (defmacro abc (arg) 1) (defun def () (abc 2))))