From 159602cb70ad4f49cad46a6f90dbe2b9091355db Mon Sep 17 00:00:00 2001 From: Zach Shaftel Date: Sat, 14 Jun 2025 20:57:21 -0400 Subject: [PATCH] Fix byte-compilation of defalias with a constant macro cons pair * lisp/emacs-lisp/bytecomp.el (byte-compile-file-form-defalias): Quote the function name in '(macro . function-name), since we eval it later. * test/lisp/emacs-lisp/bytecomp-tests.el (test-eager-load-macro-expand-defalias): New test. (Bug#78792) (cherry picked from commit 075ebed98fea274b363d4d015b32edb0a12a9a89) --- lisp/emacs-lisp/bytecomp.el | 3 ++- test/lisp/emacs-lisp/bytecomp-tests.el | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 452765c4c38..d4e317301b6 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -5189,7 +5189,8 @@ binding slots have been popped." (pcase-let* ;; `macro' is non-nil if it defines a macro. ;; `fun' is the function part of `arg' (defaults to `arg'). - (((or (and (or `(cons 'macro ,fun) `'(macro . ,fun)) (let macro t)) + (((or (and (or `(cons 'macro ,fun) `'(macro . ,(app (list 'quote) fun))) + (let macro t)) (and (let fun arg) (let macro nil))) arg) ;; `lam' is the lambda expression in `fun' (or nil if not diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index d1f272f7a4d..7382928da15 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el @@ -1322,6 +1322,24 @@ byte-compiled. Run with dynamic binding." (defun def () (m)))) (should (equal (funcall 'def) 4))) +(ert-deftest test-eager-load-macro-expand-defalias () + (ert-with-temp-file elfile + :suffix ".el" + (write-region + (concat ";;; -*- lexical-binding: t -*-\n" + (mapconcat #'prin1-to-string + '((defalias 'nothing '(macro . ignore)) + (defalias 'something (cons 'macro #'identity)) + (defalias 'five (cons 'macro (lambda (&rest _) 5))) + (eval-when-compile + (defun def () (or (nothing t) (something (five nil)))))) + "\n")) + nil elfile) + (let* ((byte-compile-debug t) + (byte-compile-dest-file-function #'ignore)) + (byte-compile-file elfile) + (should (equal (funcall 'def) 5))))) + (defmacro bytecomp-tests--with-temp-file (file-name-var &rest body) (declare (indent 1)) (cl-check-type file-name-var symbol) -- 2.39.5