]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix function arity check for noncompiled callees (bug#78685)
authorMattias EngdegÄrd <mattiase@acm.org>
Thu, 5 Jun 2025 16:11:43 +0000 (18:11 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 7 Jun 2025 20:01:23 +0000 (22:01 +0200)
This is a regression from Emacs 29.

* lisp/emacs-lisp/bytecomp.el (byte-compile-fdefinition):
Make it work for functions that aren't compiled.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--f):
(bytecomp-tests--warn-arity-noncompiled-callee): Add test.

(cherry picked from commit 8b0f5b05976a99e82e54d6c602d47a8668ccd9d5)

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

index f89bf18094b570e45a66c7b0c035749de2c150a4..dce1b6f818ba9822f6c39df8ce103da886ab98f8 100644 (file)
@@ -1463,10 +1463,7 @@ when printing the error message."
        (let ((fn name))
          (while (and (symbolp fn)
                      (fboundp fn)
-                     (or (symbolp (symbol-function fn))
-                         (consp (symbol-function fn))
-                         (and (not macro-p)
-                              (compiled-function-p (symbol-function fn)))))
+                     (functionp (symbol-function fn)))
            (setq fn (symbol-function fn)))
           (let ((advertised (get-advertised-calling-convention
                              (if (and (symbolp fn) (fboundp fn))
@@ -1478,7 +1475,7 @@ when printing the error message."
               (if macro-p
                   `(macro lambda ,advertised)
                 `(lambda ,advertised)))
-             ((and (not macro-p) (compiled-function-p fn)) fn)
+             ((and (not macro-p) (functionp fn)) fn)
              ((not (consp fn)) nil)
              ((eq 'macro (car fn)) (cdr fn))
              (macro-p nil)
index 8b0c1dad4c03fd49ebee4ff47cea90a9ccc52fac..d1f272f7a4dd5dcda82b3dbf9709eed28b2809dc 100644 (file)
@@ -1357,6 +1357,20 @@ byte-compiled.  Run with dynamic binding."
                      (concat ";;; -*-lexical-binding:nil-*-\n" some-code)))
         (should (cookie-warning some-code))))))
 
+(defun bytecomp-tests--f (x y &optional u v) (list x y u v))
+
+(ert-deftest bytecomp-tests--warn-arity-noncompiled-callee ()
+  "Check that calls to non-compiled functions are arity-checked (bug#78685)"
+  (should (not (compiled-function-p (symbol-function 'bytecomp-tests--f))))
+  (let* ((source (concat ";;; -*-lexical-binding:t-*-\n"
+                         "(defun my-fun () (bytecomp-tests--f 11))\n"))
+         (lexical-binding t)
+         (log (bytecomp-tests--log-from-compilation source)))
+    (should (string-search
+             (concat "Warning: `bytecomp-tests--f' called with 1 argument,"
+                     " but requires 2-4")
+             log))))
+
 (ert-deftest bytecomp-tests--unescaped-char-literals ()
   "Check that byte compiling warns about unescaped character
 literals (Bug#20852)."