很早之前就看过你写的那篇 浅析Elisp中的compiler macro,一年前我写一个关于在 Emacs 中使用内联函数的总结的时候很有帮助。在测试 cl-defsubst 的时候,和你在帖子里描述的错误一致。那时候我用的是 Emacs 28.2。
不过这个 bug 在这个 commit 中被修复了: Faster and less wrong cl-defsubst inlining,现在 cl-defsubst 也能正常展开了。下面分别是我在 Emacs 29.2 和 Emacs 30.0.50 中得到的结果:
;; 29.2
(cl-defsubst my-test1 (x) (let ((y 5)) (+ x y)))
(macroexpand-all '(my-test1 y))
⇒ (let ((y 5)) (+ y y))
;; 30.0.50
(cl-defsubst my-test1 (x) (let ((y 5)) (+ x y)))
(macroexpand-all '(my-test1 y))
⇒ (let* ((x y)) (let ((y 5)) (+ x y)))